@need 3200

@node VU Utilities
@chapter VU Utilities

These functions provide higher-level abstractions that capture common
ways of using the lower-level VU functions.

@sp 1
@need 1750
@noindent
@b{* Function} @code{vu_file_to_string}@fuindex vu_file_to_string
@*
@example
@group
int vu_file_to_string (int * errn,
                       t_uchar ** buf,
                       size_t * len,
                       int fd);
@end group
@group
@end group
@end example

Read the entire contents of @code{fd} into a newly allocated string.


If no error occurs, return @code{0}.  The new string is returned in @code{*buf};
its length in @code{*len}.


If an I/O error occurs, return @code{-1} and fill @code{*errn}.


If @code{vu_fstat} is able to report the length of the file, a single call to 
@code{vu_read_retry} is used to read its contents.  Otherwise, repeated calls
to @code{vu_read_retry} are used.

@sp 1
@need 1750
@noindent
@b{* Function} @code{vu_move_fd}@fuindex vu_move_fd
@*
@example
@group
int vu_move_fd (int * errn, int fd, int newfd);
@end group
@group
@end group
@end example

Relocate @code{fd} to @code{newfd}.  @code{fd} must already be handled by VU.


Thus function performs a @code{vu_dup} or @code{vu_dup2}


This is useful when performing file redirections after @code{fork} and
before @code{exec}.

@sp 1
@need 1750
@noindent
@b{* Function} @code{vu_file_is_directory}@fuindex vu_file_is_directory
@*
@example
@group
int vu_file_is_directory (int * errn, t_uchar * name);
@end group
@group
@end group
@end example

Return @code{1} if @code{name} names a directory, @code{0} if not, @code{-1} on error.


Non-existence of any file called @code{name} is not an error.

@sp 1
@need 1750
@noindent
@b{* Function} @code{vu_file_is_directory_following}@fuindex vu_file_is_directory_following
@*
@example
@group
int vu_file_is_directory_following (int * errn, t_uchar * name);
@end group
@group
@end group
@end example

Return @code{1} if @code{name} names a directory or symlink to a directory, 
@code{0} if not, @code{-1} on error.


Non-existence of any file called @code{name} is not an error.




