ftp.nice.ch/Attic/openStep/implementation/gnustep/sources/alpha-snapshots/pthreads.0.9.2.tgz#/pthreads-0.9.2/stdlib/utils.h

This is utils.h in view mode; [Download] [Up]

/*
 * --  utils.h
 */
#ifndef _utils_
#define _utils_
#include <pthread.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <dirent.h>
#include <stdio.h>

#if __STDC__
# include <stdarg.h>
#else
# include <varargs.h>       /* It's a BSD system */
#endif

#ifdef __cplusplus
extern "C" {
#endif

extern int
fprintf_r( FILE *stream, const char *format, ... );

extern int
printf_r( const char *format, ... );

extern void *
malloc_r( size_t bytes );

extern void
free_r( void *ptr );

extern struct dirent *
readdir_r( DIR *dir );

extern DIR *
opendir_r( const char *name );

extern int
closedir_r( DIR *dp );

extern void
print_system_counters( void );

extern int
create_joinable( pthread_t *th, thread_proc_t proc, void *arg );

extern char *
strchr_r( const char *s, int c );

extern char *
strrchr_r( const char *s, int c );

extern char *
strcpy_r( char *dest, const char *src );

extern char *
strncpy_r( char *dest, const char *src, size_t n );

extern size_t
strlen_r( const char *s );

extern int
strcmp_r( const char *s1, const char *s2 );

extern int
strncmp_r( const char *s1, const char *s2, size_t p );

extern long
strtol_r( const char *nptr, char **endptr, int base );

extern char *
strerror_r( int errno );

extern char *
strcat_r( char *dest, const char *src );

extern char *
strncat_r( char *dest, const char *src, size_t n );

extern int
stat_r( const char *file_name, struct stat *buf );

extern int
fstat_r( int filedes, struct stat *buf );

extern int
lstat_r( const char *file_name, struct stat *buf );

#define THREAD_SUCCESS ((void *)SUCCESS)
#define THREAD_FAILURE ((void *)FAILURE)

#define CHECK(status,msg) \
{ \
    if( status != SUCCESS ) \
    { \
        fprintf_r(stderr, "%s at line %d in %s:", msg, __LINE__, __FILE__ ); \
        fprintf_r(stderr, "%s!\n", sys_errlist[status] ); \
        pthread_exit( THREAD_FAILURE ); \
    } \
}

/*
 * If you are not using a thread-safe standard library, you can compile your
 * program using the _THREAD_SAFE_ definition.  This will redefine a few of the
 * more common standard library routines to the thread-safe counter parts
 * defined in this module.
 */
#ifdef _THREAD_SAFE_

#define fprintf     fprintf_r
#define printf      printf_r
#define malloc      malloc_r
#define free        free_r
#define readdir     readdir_r
#define opendir     opendir_r
#define closedir    closedir_r
#define strchr      strchr_r
#define strrcjr     strrchr_r
#define strcpy      strcpy_r
#define strncpy     strncpy_r
#define strlen      strlen_r
#define strcmp      strcmp_r
#define strncmp     strncmp_r
#define strtol      strtol_r
#define strerror    strerror_r
#define strcat      strcat_r
#define strncat     strncat_r
#define stat        stat_r
#define fstat       fstat_r
#define lstat       lstat_r

#endif /* _THREAD_SAFE_ */


#ifdef __cplusplus
}
#endif
#endif

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.