1
/* Copyright (C) 1995 Bjoern Beutel. */
3
/* Description. =============================================================*/
5
/* Operations for files and file names. */
7
/* File operations. =========================================================*/
9
extern bool_t file_exists( string_t file_name );
10
/* Return TRUE iff file FILE_NAME exists. */
12
extern FILE *open_stream( string_t file_name, string_t stream_mode );
13
/* Open file FILE_NAME and create a stream from/to it in mode STREAM_MODE.
14
* Works like "fopen", but calls "error" if it doesn't work. */
16
extern void close_stream( FILE **stream_p, string_t file_name );
17
/* Close the stream *STREAM_P which is connected to the file FILE_NAME
18
* and set *STREAM_P to NULL. Don't do anything if *STREAM_P == NULL.
19
* Works like "fclose", but calls "error" if FILE_NAME != NULL and an error
20
* occurs during closing. */
22
extern void write_vector( void *address,
27
/* Write ITEM_COUNT items, of size ITEM_SIZE each, stored at *ADDRESS,
28
* to STREAM, which is connected to file FILE_NAME.
29
* Works like "fwrite", but calls "error" if it doesn't work. */
31
extern void read_vector( void *address,
36
/* Read ITEM_COUNT items, of size ITEM_SIZE each, from STREAM,
37
* which is connected to file FILE_NAME, and store them at *ADDRESS.
38
* Works like "fread", but calls "error" if it doesn't work. */
40
extern void *read_new_vector( int_t item_size,
44
/* Read ITEM_COUNT items, of size ITEM_SIZE each, from STREAM,
45
* which is connected to file FILE_NAME, into allocated memory block,
46
* and return a pointer to that block. */
48
extern void map_file( string_t file_name, void **address, int_t *length );
49
/* Map file "file_name" into the memory. It will be available in the
50
* memory region starting at *ADDRESS and will occupy LENGTH bytes.
51
* After usage, return the memory region via "unmap_file". */
53
extern void unmap_file( void **address, int_t length );
54
/* Return the memory region that has been allocated by "map_file".
55
* The region starts at *ADDRESS and occupies LENGTH bytes. */
57
/* File name operations. ====================================================*/
59
extern string_t name_in_path( string_t path_name );
60
/* Return the file name in PATH_NAME, i.e. the name after the last "/". */
62
extern string_t replace_vars_in_string( string_t string );
63
/* Replace environment variables of form "$(X)" in STRING.
64
* Return the resulting string. It must be freed after use. */
66
extern string_t absolute_path( string_t src_path, string_t relative_to );
67
/* Return the absolute path name which is equivalent to SRC_PATH.
68
* If SRC_PATH starts with "~", it's replaced by the home directory of the
69
* user whose login name is following (current user if no login name).
70
* If RELATIVE_TO is not NULL, SRC_NAME is relative to that path name.
71
* RELATIVE_TO must be an absolute path name (a directory or a file).
72
* The returned path must be freed after use. */
74
extern bool_t has_extension( string_t file_name, string_t extension );
75
/* Test if FILE_NAME has extension EXTENSION. */
77
extern string_t replace_extension( string_t file_name, string_t extension );
78
/* Return a new string that contains FILE_NAME with new EXTENSION.
79
* The string must be freed after use. */
81
extern void set_file_name( string_t *file_name_p, string_t file_name );
82
/* Set *FILE_NAME_P to FILE_NAME, converted to absolute path.
83
* Print an error if *FILE_NAME_P is already set.
84
* The created file name must be freed after use. */
86
extern void set_binary_file_name( string_t *file_name_p, string_t file_name );
87
/* Set *FILE_NAME_P to
88
* FILE_NAME plus "_l" for little endian, "_b" for big endian, "_c" else,
89
* converted to absolute path.
90
* Print an error if *FILE_NAME_P is already set.
91
* The created file name must be freed after use. */
93
/* End of file. =============================================================*/