source: trunk/drmaa_utils/drmaa_utils/util.h @ 1

Revision 1, 4.4 KB checked in by mmamonski, 13 years ago (diff)

Torque/PBS DRMAA initial commit

Line 
1/* $Id: util.h 2 2009-10-12 09:51:22Z mamonski $ */
2/*
3 *  FedStage DRMAA utilities library
4 *  Copyright (C) 2006-2008  FedStage Systems
5 *
6 *  This program is free software: you can redistribute it and/or modify
7 *  it under the terms of the GNU General Public License as published by
8 *  the Free Software Foundation, either version 3 of the License, or
9 *  (at your option) any later version.
10 *
11 *  This program is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/**
21 * @file util.h
22 * Various functions.
23 */
24
25#ifndef __DRMAA_UTILS__UTIL_H
26#define __DRMAA_UTILS__UTIL_H
27
28#ifdef HAVE_CONFIG_H
29#       include <config.h>
30#endif
31
32#include <time.h>
33
34#include <drmaa_utils/common.h>
35#include <drmaa_utils/compat.h>
36
37char *fsd_explode( const char *const *vector, char glue, int n );
38void fsd_free_vector( char **vector );
39char **fsd_copy_vector( const char *const * vector );
40char *fsd_replace( char *input, const char *placeholder, const char *value );
41
42char *fsd_strdup( const char *s );
43char *fsd_strndup( const char *s, size_t n );
44
45int fsd_atoi( const char *s );
46
47void
48fsd_str_append(
49                bool *truncated,
50                char **p, char *end,
51                const char *fmt, ...
52                )
53                __attribute__(( format( printf, 4, 5 ) ));
54
55size_t
56fsd_snprintf(
57                bool *truncated,
58                char *str, size_t size,
59                const char *fmt, ...
60                )
61                __attribute__(( format( printf, 4, 5 ) ));
62
63size_t
64fsd_vsnprintf(
65                bool *truncated,
66                char *str, size_t size,
67                const char *fmt, va_list args
68                );
69
70/**
71 * Behaves like asprintf function from standard C library
72 * except any errors are marked in error context structure.
73 *
74 * It substitutes `%m` format string as in glibc
75 * (with `strerror(errno)`).
76 */
77char *fsd_asprintf( const char *fmt, ... )
78                __attribute__(( format( __printf__, 1, 2 ) ));
79
80/**
81 * Behaves like vasprintf function from standard C library
82 * except any errors are marked in error context structure.
83 */
84char *fsd_vasprintf( const char *fmt, va_list args );
85
86/**
87 * Implements GNU version of strerror_r function - thread-safe
88 * function returning message describing error code.
89 *
90 * From Linux Programmer's Manual:
91 *
92 * <code> char *strerror_r(int errnum, char *buf, size_t buflen); </code>
93 *
94 * The GNU-specific strerror_r() returns a pointer to a string containing
95 * the error message.  This may be either a pointer to a string that the
96 * function stores in buf, or a pointer to some (immutable) static string
97 * (in which case buf is unused).  If the function stores a string in
98 * buf, then at most buflen bytes are stored (the string may be truncated
99 * if buflen is too small) and the string always includes a terminating
100 * null byte.
101 */
102const char *
103fsd_strerror_r( int errnum, char *buffer, size_t buffer_size );
104
105char *
106fsd_astrerror( int errnum, bool *malloced );
107
108/** Retrievs current system timestamp. */
109void fsd_get_time( struct timespec *ts );
110
111/** Add delta to timestamp. */
112void fsd_ts_add( struct timespec *a, const struct timespec *b );
113
114/**
115 * Compares two timestamps.
116 * @return Negative integer when a < b (a represents earlier timestamp),
117 *   positive integer when a > b or 0 when timestamps are equal.
118 */
119int fsd_ts_cmp( const struct timespec *a, const struct timespec *b );
120
121/**
122 * Reads file contents.
123 * @param filename  Path to the file.
124 * @param must_exist  Controls behaviour when file not exist
125 *   (or is not readable).  If set to \c true DRMAA_ERRNO_INTERNAL_ERROR
126 *   is raised on such occasion.  If set to \c false only
127 *   \a content is set to \c NULL and no error is raised.
128 * @param content  Filled with pointer to buffer with file contents
129 *   or \c NULL when error is encoureged.  Caller is responsible
130 *   for free()'ing it.
131 * @param length  Filled with length of \a content buffer.
132 */
133void
134fsd_read_file(
135                const char *filename, bool must_exist,
136                char **content, size_t *length
137                );
138
139/**
140 * Gets path to current working directory.
141 * @return  Path to process's current working directory
142 *   in malloc'ed '\0' terminated buffer
143 *   or \c NULL in case of error.
144 */
145char *
146fsd_getcwd(void);
147
148/**
149 * Returns signal name.
150 * @param signum  Valid signal number.
151 */
152const char *
153fsd_strsignal( int signum );
154
155#endif /* __DRMAA_UTILS__UTIL_H */
Note: See TracBrowser for help on using the repository browser.