digitalmars.com                      
Last update Sun Mar 4 12:00:59 2018

util.h

These are very useful utility functions. They aren't part of any standard, but ought to be.

file_append

Header
util.h
Prototype
int file_append(const char *name, void *buffer, size_t size);
Description
Takes the number of bytes specified by size pointed to by buffer and appends it to the file specified by name. If the file does not exist, it is created. The append is always done in binary mode; no CR-LF translation is done.

file_append() is very useful for maintaining log files.

Return Value
0 if successful. Otherwise, returns the error code.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
file_read file_write

file_read

Header
util.h
Prototype
int file_read(const char *name, void **pbuffer, size_t *psize);
Description
Reads the contents of the file specified by name into a buffer. The buffer is allocated by malloc(), and a pointer to it is returned in *pbuffer. *psize is set to the length of the file.

The read is always done in binary mode; no CR-LF translation is done.

In 16 bit memory models, an extra byte is always stored at buffer[size]. This makes it safe to use functions on it that rely on 0 terminated strings. 32 bit memory models have three 0 bytes after the end, this insures that not only will char string scans terminate, but wide character scanning functions as well. Having a guaranteed 0 at the end makes for faster scans of the data because a length check is not needed unless a zero is encountered.

Return Value
0 if successful. Otherwise, returns the error code.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
file_read file_write

file_write

Header
util.h
Prototype
int file_write(const char *name, void *buffer, size_t size);
Description
Takes the number of bytes specified by size pointed to by buffer and writes it to the file specified by name. The write is always done in binary mode; no CR-LF translation is done.
Return Value
0 if successful. Otherwise, returns the error code.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
file_append file_read
Home | Compiler & Tools | IDDE Reference | STL | Search | Download | Forums