File: UTILS_IO.h

package info (click to toggle)
otf2 3.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 28,980 kB
  • sloc: ansic: 92,997; python: 16,977; cpp: 9,057; sh: 6,299; makefile: 235; awk: 54
file content (185 lines) | stat: -rw-r--r-- 6,894 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * This file is part of the Score-P software ecosystem (http://www.score-p.org)
 *
 * Copyright (c) 2009-2012,
 * RWTH Aachen University, Germany
 *
 * Copyright (c) 2009-2012,
 * Gesellschaft fuer numerische Simulation mbH Braunschweig, Germany
 *
 * Copyright (c) 2009-2012, 2014,
 * Technische Universitaet Dresden, Germany
 *
 * Copyright (c) 2009-2012,
 * University of Oregon, Eugene, USA
 *
 * Copyright (c) 2009-2012,
 * Forschungszentrum Juelich GmbH, Germany
 *
 * Copyright (c) 2009-2012,
 * German Research School for Simulation Sciences GmbH, Juelich/Aachen, Germany
 *
 * Copyright (c) 2009-2012,
 * Technische Universitaet Muenchen, Germany
 *
 * This software may be modified and distributed under the terms of
 * a BSD-style license.  See the COPYING file in the package base
 * directory for details.
 *
 */

#ifndef UTILS_IO_H
#define UTILS_IO_H

#ifdef __cplusplus
extern "C"
{
#endif

#ifndef __cplusplus
#include <stdbool.h>
#endif
#include <stddef.h>
#include <stdio.h>

#include <UTILS_Error.h>

/**
   Checks whether a file exists.
   @param filename  The name of the file which is checked.
   @returns true if the file exists, else false.
 */
#define UTILS_IO_DoesFileExist PACKAGE_MANGLE_NAME( UTILS_IO_DoesFileExist )
bool
UTILS_IO_DoesFileExist( const char* filename );

/**
   Gives the path to the executeable name (argv[0]) without the executable
   name and trailing slash. Checks whether the given name contains path
   information. If not, it searches the directories in the PATH environment
   variable.
   @param exe    The executable name as given to argv[0].
   @returns The path to the executable without the executable name itself and
            trailing slash. If no path was found, NULL is returned.
 */
#define UTILS_IO_GetExecutablePath PACKAGE_MANGLE_NAME( UTILS_IO_GetExecutablePath )
char*
UTILS_IO_GetExecutablePath( const char* exe );

/**
 * Reads a line until a newline from @a file. The line is stored in the buffer
 * pointed to by @a buffer. If the buffer is not large enough, the buffer is reallocated
 * to contain the whole line. The current size of the buffer is stored in @a buffer_size.
 * @param buffer      Pointer to a storage location, where the pointer to an allocated
 *                    memory block is stored, to which the read line written. If the
 *                    memory block is too small it will be enlarged. The buffer must be
 *                    freed by the calling function. The pointer to the buffer must not
 *                    be NULL. However, *buffer may be NULL.
 * @param buffer_size Points to a memory location where the size of the memory block
 *                    pointed to by @a **buffer is stored. If the memory is resized,
 *                    the buffer_size is updated.
 * @param file        A file handle of an already open file, from which a line is read.
 * @returns PACKAGE_SUCCESS, if a line was read successfully. If the end of the file
 *          was reached, PACKAGE_ERROR_END_OF_BUFFER is returned. If an error occurred,
 *          an error code is returned. Possible error codes are:
 *          PACKAGE_ERROR_MEM_ALLOC_FAILED and PACKAGE_ERROR_FILE_INTERACTION.
 */
#define UTILS_IO_GetLine PACKAGE_MANGLE_NAME( UTILS_IO_GetLine )
PACKAGE_ErrorCode
UTILS_IO_GetLine( char**  buffer,
                  size_t* buffer_size,
                  FILE*   file );

/**
 * Returns true if @a path is a relative or absolute path.
 */
#define UTILS_IO_HasPath PACKAGE_MANGLE_NAME( UTILS_IO_HasPath )
bool
UTILS_IO_HasPath( const char* path );

/**
 * Cuts of the path prefix from a filename.
 * @param path a filename which might have a path prefix.
 * @returns a pointer to the position in @a path where the filename starts.
 */
#define UTILS_IO_GetWithoutPath PACKAGE_MANGLE_NAME( UTILS_IO_GetWithoutPath )
const char*
UTILS_IO_GetWithoutPath( const char* path );

/**
 * Simplifies the @a path. If @path contains ../ subpathes they are merged with
 * preceding pathes. Thus the final representation of the path is minimized. Furthermore,
 * /./ sequences are cut out.
 * If the original path contained at least one slash, this functions will prepend
 * a ./ if the simplified path has no more slashes. This maintains the information
 * whether the sting was a simple file name or given as a path.
 * @param path the path that is simplified. The simplified path is stored in the same
 *        location. It must not be a pointer to a constant in the program segment.
 *        Passing a pointer to a string literal results in a segmentation fault.
 */
#define UTILS_IO_SimplifyPath PACKAGE_MANGLE_NAME( UTILS_IO_SimplifyPath )
void
UTILS_IO_SimplifyPath( char* path );

/**
 * Joins an arbitrary number of path elements into one path.
 *
 * If a path element is an absolute path, any previous path elements are
 * discarded. If an path element is empty (ie. "") it is ignored.
 *
 * @param nPaths The number of variable argument entries following the
 *               @a nPaths argument.
 * @param ...    Path elements to be joined. All of type <code>const char*</code>.
 *
 * @return Joined path, allocated with @a malloc.
 */
#define UTILS_IO_JoinPath PACKAGE_MANGLE_NAME( UTILS_IO_JoinPath )
char*
UTILS_IO_JoinPath( int nPaths,
                   ... );

/**
 * Wrapper function for gethostname which is not declared or implemented on all systems
 * @param name     Pointer to a memory location of length @a namelen where the name
 *                 is stored. The result is NULL-terminated, except when the name was
 *                 too long for the memory location.
 * @param namelen  Length of the memory segment reserved for @a name.
 * @returns PACKAGE_SUCCESS if the operation was successful.
 */
#define UTILS_IO_GetHostname PACKAGE_MANGLE_NAME( UTILS_IO_GetHostname )
PACKAGE_ErrorCode
UTILS_IO_GetHostname( char*  name,
                      size_t namelen );

/**
 * Wrapper function for getcwd which is not declared or implemented on all systems.
 * Uses the same syntax as the POSIX getcwd.
 * @param buf  Points to the buffer to copy the current working directory to,
 *             of NULL if getcwd() should allocate the buffer.
 * @param size Is the size, in bytes, of the array of characters that buf points to.
 */
#define UTILS_IO_GetCwd PACKAGE_MANGLE_NAME( UTILS_IO_GetCwd )
char*
UTILS_IO_GetCwd( char*  buf,
                 size_t size );

/**
 * File copy
 *
 * @param sourceFileName filename of the source file
 * @param destFileName   filename of the target file
 *
 * @returns zero if the operation was successful. If an error occurred,
 *          a PACKAGE_ERROR_FILE_CAN_NOT_OPEN error code is returned.
 */
PACKAGE_ErrorCode
#define UTILS_IO_FileCopy PACKAGE_MANGLE_NAME( UTILS_IO_FileCopy )
UTILS_IO_FileCopy( const char* sourceFileName,
                   const char* destFileName );

#ifdef __cplusplus
}
#endif


#endif /* UTILS_IO_H */