Changeset 7f9df7b9 in mainline
- Timestamp:
- 2018-01-22T22:42:57Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7a08c70
- Parents:
- e0f47f5
- Location:
- uspace/lib/posix
- Files:
-
- 1 deleted
- 50 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/Makefile
re0f47f5 r7f9df7b9 37 37 LIBC_FILE = $(LIBC_PREFIX)/libc.a 38 38 39 FIXED_POSIX_LIBRARY = libposixaslibc.a40 39 FIXED_C_LIBRARY = libc4posix.a 41 40 MERGED_C_LIBRARY = libc.a 42 41 MERGE_LIBRARIES = \ 43 42 $(FIXED_C_LIBRARY) \ 44 $( FIXED_POSIX_LIBRARY)\43 $(LIBRARY).a \ 45 44 $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a \ 46 45 $(LIBSOFTINT_PREFIX)/libsoftint.a 47 46 48 47 REDEFS_HIDE_LIBC = redefs-hide-libc-symbols.list 49 REDEFS_SHOW_LIBPOSIX = redefs-show-posix-symbols.list50 COLLISIONS_LIST = collisions.list51 48 52 49 PRE_DEPEND = $(INCLUDE_LIBC) … … 54 51 $(INCLUDE_LIBC) \ 55 52 $(REDEFS_HIDE_LIBC) \ 56 $(REDEFS_SHOW_LIBPOSIX) \57 $(COLLISIONS_LIST) \58 53 libc.o 59 54 … … 65 60 src/fcntl.c \ 66 61 src/fnmatch.c \ 67 src/getopt.c \68 62 src/locale.c \ 69 63 src/pthread/condvar.c \ … … 94 88 ln -s -f -n ../$^ $@ 95 89 96 $(FIXED_C_LIBRARY): $(LIBC_FILE) $(REDEFS_HIDE_LIBC) $(REDEFS_SHOW_LIBPOSIX)90 $(FIXED_C_LIBRARY): $(LIBC_FILE) $(REDEFS_HIDE_LIBC) 97 91 $(OBJCOPY) --redefine-syms=$(REDEFS_HIDE_LIBC) $(LIBC_FILE) $@ 98 $(OBJCOPY) --redefine-syms=$(REDEFS_SHOW_LIBPOSIX) $@ $@99 100 $(FIXED_POSIX_LIBRARY): $(LIBRARY).a $(REDEFS_HIDE_LIBC) $(REDEFS_SHOW_LIBPOSIX)101 $(OBJCOPY) --redefine-syms=$(REDEFS_HIDE_LIBC) $(LIBRARY).a $@102 $(OBJCOPY) --redefine-syms=$(REDEFS_SHOW_LIBPOSIX) $@ $@103 92 104 93 $(MERGED_C_LIBRARY): $(MERGE_LIBRARIES) … … 106 95 $(AR) rc $@ libc.o 107 96 108 $(REDEFS_HIDE_LIBC): $( COLLISIONS_LIST)109 sed 's/.*/& __helenos_libc_&/' <$(COLLISIONS_LIST) >$@97 $(REDEFS_HIDE_LIBC): $(SOURCES) 98 sed -n -e 's/_HIDE_LIBC_SYMBOL(\(.*\))/\1 __helenos_libc_\1/p' $(SOURCES) >$@ 110 99 111 $(REDEFS_SHOW_LIBPOSIX): $(COLLISIONS_LIST)112 sed 's/.*/posix_& &/' <$(COLLISIONS_LIST) >$@113 114 $(COLLISIONS_LIST): include/posix/*.h include/posix/*/*.h115 find ./include/posix -name '*.h' -exec \116 sed -n -e '/^#/d' -e 's/__POSIX_DEF__/\n&/gp' {} \; | \117 sed -n -e 's/__POSIX_DEF__(\([^)]*\)).*/\1/p' | \118 sort -u >$@ -
uspace/lib/posix/include/posix/ctype.h
re0f47f5 r7f9df7b9 37 37 #define POSIX_CTYPE_H_ 38 38 39 #ifndef __POSIX_DEF__40 #define __POSIX_DEF__(x) x41 #endif42 43 39 #include "libc/ctype.h" 44 40 -
uspace/lib/posix/include/posix/dirent.h
re0f47f5 r7f9df7b9 36 36 #define POSIX_DIRENT_H_ 37 37 38 #ifndef __POSIX_DEF__39 #define __POSIX_DEF__(x) x40 #endif41 42 38 #include <libc/dirent.h> 43 39 -
uspace/lib/posix/include/posix/dlfcn.h
re0f47f5 r7f9df7b9 34 34 #define POSIX_DLFCN_H_ 35 35 36 #ifndef __POSIX_DEF__ 37 #define __POSIX_DEF__(x) x 38 #endif 36 #include "libc/dlfcn.h" 39 37 40 38 #define RTLD_LAZY 1 … … 43 41 #define RTLD_LOCAL 0 44 42 45 46 extern void *__POSIX_DEF__(dlopen)(const char *, int); 47 extern void *__POSIX_DEF__(dlsym)(void *, const char *); 48 extern int __POSIX_DEF__(dlclose)(void *); 49 extern char *__POSIX_DEF__(dlerror)(void); 50 43 extern void *dlopen(const char *, int); 44 extern void *dlsym(void *, const char *); 45 extern int dlclose(void *); 46 extern char *dlerror(void); 51 47 52 48 #endif -
uspace/lib/posix/include/posix/fcntl.h
re0f47f5 r7f9df7b9 35 35 #ifndef POSIX_FCNTL_H_ 36 36 #define POSIX_FCNTL_H_ 37 38 #ifndef __POSIX_DEF__39 #define __POSIX_DEF__(x) x40 #endif41 37 42 38 #include "sys/types.h" … … 93 89 #define FD_CLOEXEC 1 /* Close on exec. */ 94 90 95 extern int __POSIX_DEF__(open)(const char *pathname, int flags, ...); 96 extern int __POSIX_DEF__(fcntl)(int fd, int cmd, ...); 97 91 extern int open(const char *pathname, int flags, ...); 92 extern int fcntl(int fd, int cmd, ...); 98 93 99 94 #endif /* POSIX_FCNTL_H_ */ -
uspace/lib/posix/include/posix/fenv.h
re0f47f5 r7f9df7b9 37 37 #define POSIX_FENV_H_ 38 38 39 40 39 #define FE_DIVBYZERO 1 41 40 #define FE_INEXACT 2 -
uspace/lib/posix/include/posix/fnmatch.h
re0f47f5 r7f9df7b9 36 36 #define POSIX_FNMATCH_H_ 37 37 38 #ifndef __POSIX_DEF__39 #define __POSIX_DEF__(x) x40 #endif41 42 38 /* Error Values */ 43 39 #undef FNM_NOMATCH … … 60 56 #define FNM_CASEFOLD 16 61 57 62 extern int __POSIX_DEF__(fnmatch)(const char *pattern, const char *string, int flags);58 extern int fnmatch(const char *pattern, const char *string, int flags); 63 59 64 60 -
uspace/lib/posix/include/posix/getopt.h
re0f47f5 r7f9df7b9 35 35 #define POSIX_GETOPT_H 36 36 37 #ifndef __POSIX_DEF__38 #define __POSIX_DEF__(x) x39 #endif40 41 37 #include "unistd.h" 42 38 … … 55 51 #endif 56 52 57 extern int __POSIX_DEF__(getopt_long)(int, char * const [], const char *, const struct option *, int *);53 extern int getopt_long(int, char * const [], const char *, const struct option *, int *); 58 54 59 55 -
uspace/lib/posix/include/posix/inttypes.h
re0f47f5 r7f9df7b9 36 36 #define POSIX_INTTYPES_H_ 37 37 38 #ifndef __POSIX_DEF__39 #define __POSIX_DEF__(x) x40 #endif41 42 38 #include "stdint.h" 43 39 #include "libc/inttypes.h" -
uspace/lib/posix/include/posix/locale.h
re0f47f5 r7f9df7b9 36 36 #define POSIX_LOCALE_H_ 37 37 38 #ifndef __POSIX_DEF__39 #define __POSIX_DEF__(x) x40 #endif41 42 38 #include <_bits/NULL.h> 43 39 44 40 #ifndef __locale_t_defined 45 41 #define __locale_t_defined 46 typedef struct __posix_locale * __POSIX_DEF__(locale_t);42 typedef struct __posix_locale *locale_t; 47 43 #ifndef LIBPOSIX_INTERNAL 48 #define locale_t __POSIX_DEF__(locale_t)44 #define locale_t locale_t 49 45 #endif 50 46 #endif … … 84 80 #define LC_GLOBAL_LOCALE NULL 85 81 86 struct __POSIX_DEF__(lconv){82 struct lconv { 87 83 char *currency_symbol; 88 84 char *decimal_point; … … 111 107 }; 112 108 113 extern char * __POSIX_DEF__(setlocale)(int category, const char *locale);114 extern struct __POSIX_DEF__(lconv) *__POSIX_DEF__(localeconv)(void);109 extern char *setlocale(int category, const char *locale); 110 extern struct lconv *localeconv(void); 115 111 116 112 /* POSIX Extensions */ 117 extern __POSIX_DEF__(locale_t) __POSIX_DEF__(duplocale)(__POSIX_DEF__(locale_t)locobj);118 extern void __POSIX_DEF__(freelocale)(__POSIX_DEF__(locale_t)locobj);119 extern __POSIX_DEF__(locale_t) __POSIX_DEF__(newlocale)(int category_mask, const char *locale,120 __POSIX_DEF__(locale_t)base);121 extern __POSIX_DEF__(locale_t) __POSIX_DEF__(uselocale)(__POSIX_DEF__(locale_t)newloc);113 extern locale_t duplocale(locale_t locobj); 114 extern void freelocale(locale_t locobj); 115 extern locale_t newlocale(int category_mask, const char *locale, 116 locale_t base); 117 extern locale_t uselocale(locale_t newloc); 122 118 123 119 -
uspace/lib/posix/include/posix/pthread.h
re0f47f5 r7f9df7b9 32 32 #ifndef POSIX_PTHREAD_H_ 33 33 #define POSIX_PTHREAD_H_ 34 35 #ifndef __POSIX_DEF__36 #define __POSIX_DEF__(x) x37 #endif38 34 39 35 #include "libc/thread.h" … … 99 95 extern int pthread_cond_signal(pthread_cond_t *); 100 96 extern int pthread_cond_timedwait(pthread_cond_t *__restrict__, 101 pthread_mutex_t *__restrict__, const struct __POSIX_DEF__(timespec)*__restrict__);97 pthread_mutex_t *__restrict__, const struct timespec *__restrict__); 102 98 extern int pthread_cond_wait(pthread_cond_t *__restrict__, 103 99 pthread_mutex_t *__restrict__); -
uspace/lib/posix/include/posix/pwd.h
re0f47f5 r7f9df7b9 36 36 #define POSIX_PWD_H_ 37 37 38 #ifndef __POSIX_DEF__39 #define __POSIX_DEF__(x) x40 #endif41 42 38 #include "sys/types.h" 43 39 44 struct __POSIX_DEF__(passwd){40 struct passwd { 45 41 char *pw_name; 46 __POSIX_DEF__(uid_t)pw_uid;47 __POSIX_DEF__(gid_t)pw_gid;42 uid_t pw_uid; 43 gid_t pw_gid; 48 44 char *pw_dir; 49 45 char *pw_shell; 50 46 }; 51 47 52 extern struct __POSIX_DEF__(passwd) *__POSIX_DEF__(getpwent)(void);53 extern void __POSIX_DEF__(setpwent)(void);54 extern void __POSIX_DEF__(endpwent)(void);48 extern struct passwd *getpwent(void); 49 extern void setpwent(void); 50 extern void endpwent(void); 55 51 56 extern struct __POSIX_DEF__(passwd) *__POSIX_DEF__(getpwnam)(const char *name);57 extern int __POSIX_DEF__(getpwnam_r)(const char *name, struct __POSIX_DEF__(passwd)*pwd,58 char *buffer, size_t bufsize, struct __POSIX_DEF__(passwd)**result);52 extern struct passwd *getpwnam(const char *name); 53 extern int getpwnam_r(const char *name, struct passwd *pwd, 54 char *buffer, size_t bufsize, struct passwd **result); 59 55 60 extern struct __POSIX_DEF__(passwd) *__POSIX_DEF__(getpwuid)(__POSIX_DEF__(uid_t)uid);61 extern int __POSIX_DEF__(getpwuid_r)(__POSIX_DEF__(uid_t) uid, struct __POSIX_DEF__(passwd)*pwd,62 char *buffer, size_t bufsize, struct __POSIX_DEF__(passwd)**result);56 extern struct passwd *getpwuid(uid_t uid); 57 extern int getpwuid_r(uid_t uid, struct passwd *pwd, 58 char *buffer, size_t bufsize, struct passwd **result); 63 59 64 60 -
uspace/lib/posix/include/posix/signal.h
re0f47f5 r7f9df7b9 36 36 #define POSIX_SIGNAL_H_ 37 37 38 #ifndef __POSIX_DEF__39 #define __POSIX_DEF__(x) x40 #endif41 42 38 #include "sys/types.h" 43 39 #include <posix/ucontext.h> … … 63 59 int si_errno; 64 60 65 __POSIX_DEF__(pid_t)si_pid;66 __POSIX_DEF__(uid_t)si_uid;61 pid_t si_pid; 62 uid_t si_uid; 67 63 void *si_addr; 68 64 int si_status; … … 70 66 long si_band; 71 67 72 union __POSIX_DEF__(sigval)si_value;73 } __POSIX_DEF__(siginfo_t);74 75 struct __POSIX_DEF__(sigaction){68 union sigval si_value; 69 } siginfo_t; 70 71 struct sigaction { 76 72 void (*sa_handler)(int); 77 __POSIX_DEF__(sigset_t)sa_mask;73 sigset_t sa_mask; 78 74 int sa_flags; 79 void (*sa_sigaction)(int, __POSIX_DEF__(siginfo_t)*, void *);75 void (*sa_sigaction)(int, siginfo_t *, void *); 80 76 }; 81 77 82 78 83 /* Values of __POSIX_DEF__(sigevent)::sigev_notify */79 /* Values of sigevent::sigev_notify */ 84 80 #undef SIGEV_NONE 85 81 #undef SIGEV_SIGNAL … … 229 225 }; 230 226 231 extern int __POSIX_DEF__(sigaction)(int sig, const struct __POSIX_DEF__(sigaction)*__restrict__ act,232 struct __POSIX_DEF__(sigaction)*__restrict__ oact);233 234 extern void (* __POSIX_DEF__(signal)(int sig, void (*func)(int)))(int);235 extern int __POSIX_DEF__(raise)(int sig);236 extern int __POSIX_DEF__(kill)(__POSIX_DEF__(pid_t)pid, int sig);237 extern int __POSIX_DEF__(killpg)(__POSIX_DEF__(pid_t)pid, int sig);238 239 extern void __POSIX_DEF__(psiginfo)(const __POSIX_DEF__(siginfo_t)*pinfo, const char *message);240 extern void __POSIX_DEF__(psignal)(int signum, const char *message);241 242 extern int __POSIX_DEF__(sigemptyset)(__POSIX_DEF__(sigset_t)*set);243 extern int __POSIX_DEF__(sigfillset)(__POSIX_DEF__(sigset_t)*set);244 extern int __POSIX_DEF__(sigaddset)(__POSIX_DEF__(sigset_t)*set, int signo);245 extern int __POSIX_DEF__(sigdelset)(__POSIX_DEF__(sigset_t)*set, int signo);246 extern int __POSIX_DEF__(sigismember)(const __POSIX_DEF__(sigset_t)*set, int signo);247 248 extern int __POSIX_DEF__(thread_sigmask)(int how, const __POSIX_DEF__(sigset_t)*__restrict__ set,249 __POSIX_DEF__(sigset_t)*__restrict__ oset);250 extern int __POSIX_DEF__(sigprocmask)(int how, const __POSIX_DEF__(sigset_t)*__restrict__ set,251 __POSIX_DEF__(sigset_t)*__restrict__ oset);227 extern int sigaction(int sig, const struct sigaction *__restrict__ act, 228 struct sigaction *__restrict__ oact); 229 230 extern void (*signal(int sig, void (*func)(int)))(int); 231 extern int raise(int sig); 232 extern int kill(pid_t pid, int sig); 233 extern int killpg(pid_t pid, int sig); 234 235 extern void psiginfo(const siginfo_t *pinfo, const char *message); 236 extern void psignal(int signum, const char *message); 237 238 extern int sigemptyset(sigset_t *set); 239 extern int sigfillset(sigset_t *set); 240 extern int sigaddset(sigset_t *set, int signo); 241 extern int sigdelset(sigset_t *set, int signo); 242 extern int sigismember(const sigset_t *set, int signo); 243 244 extern int thread_sigmask(int how, const sigset_t *__restrict__ set, 245 sigset_t *__restrict__ oset); 246 extern int sigprocmask(int how, const sigset_t *__restrict__ set, 247 sigset_t *__restrict__ oset); 252 248 253 249 -
uspace/lib/posix/include/posix/stddef.h
re0f47f5 r7f9df7b9 36 36 #define POSIX_STDDEF_H_ 37 37 38 #ifndef __POSIX_DEF__39 #define __POSIX_DEF__(x) x40 #endif41 42 38 #include "sys/types.h" 43 39 -
uspace/lib/posix/include/posix/stdint.h
re0f47f5 r7f9df7b9 36 36 #define POSIX_STDINT_H_ 37 37 38 #ifndef __POSIX_DEF__39 #define __POSIX_DEF__(x) x40 #endif41 42 38 #include "libc/stdint.h" 43 39 -
uspace/lib/posix/include/posix/stdio.h
re0f47f5 r7f9df7b9 37 37 #define POSIX_STDIO_H_ 38 38 39 #ifndef __POSIX_DEF__ 40 #define __POSIX_DEF__(x) x 41 #endif 39 #include "libc/stdio.h" 42 40 43 41 #include "stddef.h" … … 67 65 typedef struct _IO_FILE FILE; 68 66 69 #ifndef LIBPOSIX_INTERNAL70 enum _buffer_type {71 /** No buffering */72 _IONBF,73 /** Line buffering */74 _IOLBF,75 /** Full buffering */76 _IOFBF77 };78 #endif79 80 67 extern FILE *stdin; 81 68 extern FILE *stdout; … … 130 117 #undef L_ctermid 131 118 #define L_ctermid PATH_MAX 132 extern char * __POSIX_DEF__(ctermid)(char *s);119 extern char *ctermid(char *s); 133 120 134 121 /* Error Recovery */ 135 extern void __POSIX_DEF__(clearerr)(FILE *stream);122 extern void clearerr(FILE *stream); 136 123 137 124 /* Input/Output */ 138 125 #undef putc 139 126 #define putc fputc 140 extern int __POSIX_DEF__(fputs)(const char *__restrict__ s, FILE *__restrict__ stream);127 extern int fputs(const char *__restrict__ s, FILE *__restrict__ stream); 141 128 #undef getc 142 129 #define getc fgetc 143 extern int __POSIX_DEF__(ungetc)(int c, FILE *stream);144 extern ssize_t __POSIX_DEF__(getdelim)(char **__restrict__ lineptr, size_t *__restrict__ n,130 extern int ungetc(int c, FILE *stream); 131 extern ssize_t getdelim(char **__restrict__ lineptr, size_t *__restrict__ n, 145 132 int delimiter, FILE *__restrict__ stream); 146 extern ssize_t __POSIX_DEF__(getline)(char **__restrict__ lineptr, size_t *__restrict__ n,133 extern ssize_t getline(char **__restrict__ lineptr, size_t *__restrict__ n, 147 134 FILE *__restrict__ stream); 148 135 149 136 /* Opening Streams */ 150 extern FILE * __POSIX_DEF__(freopen)(const char *__restrict__ filename,137 extern FILE *freopen(const char *__restrict__ filename, 151 138 const char *__restrict__ mode, FILE *__restrict__ stream); 152 139 153 140 /* Error Messages */ 154 extern void __POSIX_DEF__(perror)(const char *s);141 extern void perror(const char *s); 155 142 156 143 /* File Positioning */ 157 144 typedef struct { 158 145 off64_t offset; 159 } __POSIX_DEF__(fpos_t);160 161 extern int __POSIX_DEF__(fsetpos)(FILE *stream, const __POSIX_DEF__(fpos_t)*pos);162 extern int __POSIX_DEF__(fgetpos)(FILE *__restrict__ stream, __POSIX_DEF__(fpos_t)*__restrict__ pos);163 extern int __POSIX_DEF__(fseek)(FILE *stream, long offset, int whence);164 extern int __POSIX_DEF__(fseeko)(FILE *stream, __POSIX_DEF__(off_t)offset, int whence);165 extern long __POSIX_DEF__(ftell)(FILE *stream);166 extern __POSIX_DEF__(off_t) __POSIX_DEF__(ftello)(FILE *stream);146 } fpos_t; 147 148 extern int fsetpos(FILE *stream, const fpos_t *pos); 149 extern int fgetpos(FILE *__restrict__ stream, fpos_t *__restrict__ pos); 150 extern int fseek(FILE *stream, long offset, int whence); 151 extern int fseeko(FILE *stream, off_t offset, int whence); 152 extern long ftell(FILE *stream); 153 extern off_t ftello(FILE *stream); 167 154 168 155 /* Flushing Buffers */ 169 extern int __POSIX_DEF__(fflush)(FILE *stream);156 extern int fflush(FILE *stream); 170 157 171 158 /* Formatted Output */ 172 extern int __POSIX_DEF__(dprintf)(int fildes, const char *__restrict__ format, ...)159 extern int dprintf(int fildes, const char *__restrict__ format, ...) 173 160 _HELENOS_PRINTF_ATTRIBUTE(2, 3); 174 extern int __POSIX_DEF__(vdprintf)(int fildes, const char *__restrict__ format, va_list ap);175 extern int __POSIX_DEF__(sprintf)(char *__restrict__ s, const char *__restrict__ format, ...)161 extern int vdprintf(int fildes, const char *__restrict__ format, va_list ap); 162 extern int sprintf(char *__restrict__ s, const char *__restrict__ format, ...) 176 163 _HELENOS_PRINTF_ATTRIBUTE(2, 3); 177 extern int __POSIX_DEF__(vsprintf)(char *__restrict__ s, const char *__restrict__ format, va_list ap);164 extern int vsprintf(char *__restrict__ s, const char *__restrict__ format, va_list ap); 178 165 179 166 /* Formatted Input */ 180 extern int __POSIX_DEF__(fscanf)(167 extern int fscanf( 181 168 FILE *__restrict__ stream, const char *__restrict__ format, ...); 182 extern int __POSIX_DEF__(vfscanf)(169 extern int vfscanf( 183 170 FILE *__restrict__ stream, const char *__restrict__ format, va_list arg); 184 extern int __POSIX_DEF__(scanf)(const char *__restrict__ format, ...);185 extern int __POSIX_DEF__(vscanf)(const char *__restrict__ format, va_list arg);186 extern int __POSIX_DEF__(sscanf)(171 extern int scanf(const char *__restrict__ format, ...); 172 extern int vscanf(const char *__restrict__ format, va_list arg); 173 extern int sscanf( 187 174 const char *__restrict__ s, const char *__restrict__ format, ...); 188 extern int __POSIX_DEF__(vsscanf)(175 extern int vsscanf( 189 176 const char *__restrict__ s, const char *__restrict__ format, va_list arg); 190 177 191 178 /* File Locking */ 192 extern void __POSIX_DEF__(flockfile)(FILE *file);193 extern int __POSIX_DEF__(ftrylockfile)(FILE *file);194 extern void __POSIX_DEF__(funlockfile)(FILE *file);195 extern int __POSIX_DEF__(getc_unlocked)(FILE *stream);196 extern int __POSIX_DEF__(getchar_unlocked)(void);197 extern int __POSIX_DEF__(putc_unlocked)(int c, FILE *stream);198 extern int __POSIX_DEF__(putchar_unlocked)(int c);179 extern void flockfile(FILE *file); 180 extern int ftrylockfile(FILE *file); 181 extern void funlockfile(FILE *file); 182 extern int getc_unlocked(FILE *stream); 183 extern int getchar_unlocked(void); 184 extern int putc_unlocked(int c, FILE *stream); 185 extern int putchar_unlocked(int c); 199 186 200 187 /* Deleting Files */ 201 extern int __POSIX_DEF__(remove)(const char *path);188 extern int remove(const char *path); 202 189 203 190 /* Renaming Files */ 204 extern int __POSIX_DEF__(rename)(const char *oldname, const char *newname);191 extern int rename(const char *oldname, const char *newname); 205 192 206 193 /* Temporary Files */ 207 194 #undef L_tmpnam 208 195 #define L_tmpnam PATH_MAX 209 extern char * __POSIX_DEF__(tmpnam)(char *s);210 extern char * __POSIX_DEF__(tempnam)(const char *dir, const char *pfx);211 extern FILE * __POSIX_DEF__(tmpfile)(void);196 extern char *tmpnam(char *s); 197 extern char *tempnam(const char *dir, const char *pfx); 198 extern FILE *tmpfile(void); 212 199 213 200 -
uspace/lib/posix/include/posix/stdlib.h
re0f47f5 r7f9df7b9 37 37 #define POSIX_STDLIB_H_ 38 38 39 #ifndef __POSIX_DEF__40 #define __POSIX_DEF__(x) x41 #endif42 43 39 #include "sys/types.h" 44 40 … … 53 49 #define EXIT_SUCCESS 0 54 50 #define _Exit exit 55 extern int __POSIX_DEF__(atexit)(void (*func)(void));51 extern int atexit(void (*func)(void)); 56 52 extern void exit(int status) __attribute__((noreturn)); 57 53 extern void abort(void) __attribute__((noreturn)); 58 54 59 55 /* Absolute Value */ 60 extern int __POSIX_DEF__(abs)(int i);61 extern long __POSIX_DEF__(labs)(long i);62 extern long long __POSIX_DEF__(llabs)(long long i);56 extern int abs(int i); 57 extern long labs(long i); 58 extern long long llabs(long long i); 63 59 64 60 /* Integer Division */ … … 66 62 typedef struct { 67 63 int quot, rem; 68 } __POSIX_DEF__(div_t);64 } div_t; 69 65 70 66 typedef struct { 71 67 long quot, rem; 72 } __POSIX_DEF__(ldiv_t);68 } ldiv_t; 73 69 74 70 typedef struct { 75 71 long long quot, rem; 76 } __POSIX_DEF__(lldiv_t);72 } lldiv_t; 77 73 78 extern __POSIX_DEF__(div_t) __POSIX_DEF__(div)(int numer, int denom);79 extern __POSIX_DEF__(ldiv_t) __POSIX_DEF__(ldiv)(long numer, long denom);80 extern __POSIX_DEF__(lldiv_t) __POSIX_DEF__(lldiv)(long long numer, long long denom);74 extern div_t div(int numer, int denom); 75 extern ldiv_t ldiv(long numer, long denom); 76 extern lldiv_t lldiv(long long numer, long long denom); 81 77 82 78 /* Array Functions */ 83 extern void __POSIX_DEF__(qsort)(void *array, size_t count, size_t size,79 extern void qsort(void *array, size_t count, size_t size, 84 80 int (*compare)(const void *, const void *)); 85 extern void * __POSIX_DEF__(bsearch)(const void *key, const void *base,81 extern void *bsearch(const void *key, const void *base, 86 82 size_t nmemb, size_t size, int (*compar)(const void *, const void *)); 87 83 88 84 /* Environment Access */ 89 extern char * __POSIX_DEF__(getenv)(const char *name);90 extern int __POSIX_DEF__(putenv)(char *string);91 extern int __POSIX_DEF__(system)(const char *string);85 extern char *getenv(const char *name); 86 extern int putenv(char *string); 87 extern int system(const char *string); 92 88 93 89 /* Symbolic Links */ 94 extern char * __POSIX_DEF__(realpath)(const char *__restrict__ name, char *__restrict__ resolved);90 extern char *realpath(const char *__restrict__ name, char *__restrict__ resolved); 95 91 96 92 /* Floating Point Conversion */ 97 extern double __POSIX_DEF__(atof)(const char *nptr);98 extern float __POSIX_DEF__(strtof)(const char *__restrict__ nptr, char **__restrict__ endptr);99 extern double __POSIX_DEF__(strtod)(const char *__restrict__ nptr, char **__restrict__ endptr);100 extern long double __POSIX_DEF__(strtold)(const char *__restrict__ nptr, char **__restrict__ endptr);93 extern double atof(const char *nptr); 94 extern float strtof(const char *__restrict__ nptr, char **__restrict__ endptr); 95 extern double strtod(const char *__restrict__ nptr, char **__restrict__ endptr); 96 extern long double strtold(const char *__restrict__ nptr, char **__restrict__ endptr); 101 97 102 98 /* Integer Conversion */ … … 114 110 115 111 /* Memory Allocation */ 116 extern void * __POSIX_DEF__(malloc)(size_t size)112 extern void *malloc(size_t size) 117 113 __attribute__((malloc)); 118 extern void * __POSIX_DEF__(calloc)(size_t nelem, size_t elsize)114 extern void *calloc(size_t nelem, size_t elsize) 119 115 __attribute__((malloc)); 120 extern void * __POSIX_DEF__(realloc)(void *ptr, size_t size)116 extern void *realloc(void *ptr, size_t size) 121 117 __attribute__((warn_unused_result)); 122 extern void __POSIX_DEF__(free)(void *ptr);118 extern void free(void *ptr); 123 119 124 120 /* Temporary Files */ 125 extern int __POSIX_DEF__(mkstemp)(char *tmpl);121 extern int mkstemp(char *tmpl); 126 122 127 123 /* Pseudo-random number generator */ 128 extern int __POSIX_DEF__(rand)(void);129 extern void __POSIX_DEF__(srand)(unsigned int seed);124 extern int rand(void); 125 extern void srand(unsigned int seed); 130 126 131 127 /* Legacy Declarations */ 132 extern char * __POSIX_DEF__(mktemp)(char *tmpl);128 extern char *mktemp(char *tmpl); 133 129 extern int bsd_getloadavg(double loadavg[], int nelem); 134 130 -
uspace/lib/posix/include/posix/string.h
re0f47f5 r7f9df7b9 37 37 #define POSIX_STRING_H_ 38 38 39 #ifndef __POSIX_DEF__40 #define __POSIX_DEF__(x) x41 #endif42 43 39 #include "sys/types.h" 44 40 … … 74 70 75 71 /* Copying and Concatenation */ 76 extern char * __POSIX_DEF__(strcpy)(char *__restrict__ dest, const char *__restrict__ src);77 extern char * __POSIX_DEF__(strncpy)(char *__restrict__ dest, const char *__restrict__ src, size_t n);78 extern char * __POSIX_DEF__(stpcpy)(char *__restrict__ dest, const char *__restrict__ src);79 extern char * __POSIX_DEF__(stpncpy)(char *__restrict__ dest, const char *__restrict__ src, size_t n);80 extern char * __POSIX_DEF__(strcat)(char *__restrict__ dest, const char *__restrict__ src);81 extern char * __POSIX_DEF__(strncat)(char *__restrict__ dest, const char *__restrict__ src, size_t n);82 extern void * __POSIX_DEF__(memccpy)(void *__restrict__ dest, const void *__restrict__ src, int c, size_t n);83 extern char * __POSIX_DEF__(strdup)(const char *s);84 extern char * __POSIX_DEF__(strndup)(const char *s, size_t n);72 extern char *strcpy(char *__restrict__ dest, const char *__restrict__ src); 73 extern char *strncpy(char *__restrict__ dest, const char *__restrict__ src, size_t n); 74 extern char *stpcpy(char *__restrict__ dest, const char *__restrict__ src); 75 extern char *stpncpy(char *__restrict__ dest, const char *__restrict__ src, size_t n); 76 extern char *strcat(char *__restrict__ dest, const char *__restrict__ src); 77 extern char *strncat(char *__restrict__ dest, const char *__restrict__ src, size_t n); 78 extern void *memccpy(void *__restrict__ dest, const void *__restrict__ src, int c, size_t n); 79 extern char *strdup(const char *s); 80 extern char *strndup(const char *s, size_t n); 85 81 86 82 /* String/Array Comparison */ 87 extern int __POSIX_DEF__(memcmp)(const void *mem1, const void *mem2, size_t n);88 extern int __POSIX_DEF__(strcmp)(const char *s1, const char *s2);89 extern int __POSIX_DEF__(strncmp)(const char *s1, const char *s2, size_t n);83 extern int memcmp(const void *mem1, const void *mem2, size_t n); 84 extern int strcmp(const char *s1, const char *s2); 85 extern int strncmp(const char *s1, const char *s2, size_t n); 90 86 91 87 /* Search Functions */ 92 extern void * __POSIX_DEF__(memchr)(const void *mem, int c, size_t n);93 extern char * __POSIX_DEF__(strchr)(const char *s, int c);94 extern char * __POSIX_DEF__(strrchr)(const char *s, int c);88 extern void *memchr(const void *mem, int c, size_t n); 89 extern char *strchr(const char *s, int c); 90 extern char *strrchr(const char *s, int c); 95 91 extern char *gnu_strchrnul(const char *s, int c); 96 extern char * __POSIX_DEF__(strpbrk)(const char *s1, const char *s2);97 extern size_t __POSIX_DEF__(strcspn)(const char *s1, const char *s2);98 extern size_t __POSIX_DEF__(strspn)(const char *s1, const char *s2);99 extern char * __POSIX_DEF__(strstr)(const char *haystack, const char *needle);92 extern char *strpbrk(const char *s1, const char *s2); 93 extern size_t strcspn(const char *s1, const char *s2); 94 extern size_t strspn(const char *s1, const char *s2); 95 extern char *strstr(const char *haystack, const char *needle); 100 96 101 97 /* Tokenization functions. */ 102 extern char * __POSIX_DEF__(strtok_r)(char *, const char *, char **);103 extern char * __POSIX_DEF__(strtok)(char *, const char *);98 extern char *strtok_r(char *, const char *, char **); 99 extern char *strtok(char *, const char *); 104 100 105 101 106 102 /* Collation Functions */ 107 extern int __POSIX_DEF__(strcoll)(const char *s1, const char *s2);108 extern size_t __POSIX_DEF__(strxfrm)(char *__restrict__ s1, const char *__restrict__ s2, size_t n);103 extern int strcoll(const char *s1, const char *s2); 104 extern size_t strxfrm(char *__restrict__ s1, const char *__restrict__ s2, size_t n); 109 105 110 106 /* Error Messages */ 111 extern char * __POSIX_DEF__(strerror)(int errnum);112 extern int __POSIX_DEF__(strerror_r)(int errnum, char *buf, size_t bufsz);107 extern char *strerror(int errnum); 108 extern int strerror_r(int errnum, char *buf, size_t bufsz); 113 109 114 110 /* String Length */ 115 extern size_t __POSIX_DEF__(strlen)(const char *s);116 extern size_t __POSIX_DEF__(strnlen)(const char *s, size_t n);111 extern size_t strlen(const char *s); 112 extern size_t strnlen(const char *s, size_t n); 117 113 118 114 /* Signal Messages */ 119 extern char * __POSIX_DEF__(strsignal)(int signum);115 extern char *strsignal(int signum); 120 116 121 117 /* Legacy Declarations */ 122 118 #ifndef POSIX_STRINGS_H_ 123 extern int __POSIX_DEF__(ffs)(int i);124 extern int __POSIX_DEF__(strcasecmp)(const char *s1, const char *s2);125 extern int __POSIX_DEF__(strncasecmp)(const char *s1, const char *s2, size_t n);119 extern int ffs(int i); 120 extern int strcasecmp(const char *s1, const char *s2); 121 extern int strncasecmp(const char *s1, const char *s2, size_t n); 126 122 #endif 127 123 -
uspace/lib/posix/include/posix/strings.h
re0f47f5 r7f9df7b9 37 37 #define POSIX_STRINGS_H_ 38 38 39 #ifndef __POSIX_DEF__40 #define __POSIX_DEF__(x) x41 #endif42 43 44 39 #include "libc/types/common.h" 45 40 46 41 /* Search Functions */ 47 42 #ifndef POSIX_STRING_H_ 48 extern int __POSIX_DEF__(ffs)(int i);43 extern int ffs(int i); 49 44 #endif 50 45 51 46 /* String/Array Comparison */ 52 47 #ifndef POSIX_STRING_H_ 53 extern int __POSIX_DEF__(strcasecmp)(const char *s1, const char *s2);54 extern int __POSIX_DEF__(strncasecmp)(const char *s1, const char *s2, size_t n);48 extern int strcasecmp(const char *s1, const char *s2); 49 extern int strncasecmp(const char *s1, const char *s2, size_t n); 55 50 #endif 56 51 … … 62 57 63 58 /* Legacy Functions */ 64 extern int __POSIX_DEF__(bcmp)(const void *mem1, const void *mem2, size_t n);65 extern void __POSIX_DEF__(bcopy)(const void *src, void *dest, size_t n);66 extern void __POSIX_DEF__(bzero)(void *mem, size_t n);67 extern char * __POSIX_DEF__(index)(const char *s, int c);68 extern char * __POSIX_DEF__(rindex)(const char *s, int c);59 extern int bcmp(const void *mem1, const void *mem2, size_t n); 60 extern void bcopy(const void *src, void *dest, size_t n); 61 extern void bzero(void *mem, size_t n); 62 extern char *index(const char *s, int c); 63 extern char *rindex(const char *s, int c); 69 64 70 65 -
uspace/lib/posix/include/posix/sys/mman.h
re0f47f5 r7f9df7b9 36 36 #define POSIX_SYS_MMAN_H_ 37 37 38 #ifndef __POSIX_DEF__39 #define __POSIX_DEF__(x) x40 #endif41 42 38 #include "types.h" 43 39 #include <abi/mm/as.h> … … 61 57 62 58 extern void * 63 __POSIX_DEF__(mmap)(void *start, size_t length, int prot, int flags, int fd,64 __POSIX_DEF__(off_t)offset);65 extern int __POSIX_DEF__(munmap)(void *start, size_t length);59 mmap(void *start, size_t length, int prot, int flags, int fd, 60 off_t offset); 61 extern int munmap(void *start, size_t length); 66 62 67 63 -
uspace/lib/posix/include/posix/sys/stat.h
re0f47f5 r7f9df7b9 39 39 #include "types.h" 40 40 #include "../time.h" 41 42 #ifndef __POSIX_DEF__43 #define __POSIX_DEF__(x) x44 #endif45 41 46 42 /* values are the same as on Linux */ … … 112 108 #define S_ISSOCK(m) ((m & S_IFSOCK) != 0) /* socket? (Not in POSIX.1-1996.) */ 113 109 114 struct __POSIX_DEF__(stat){115 __POSIX_DEF__(dev_t)st_dev; /* ID of device containing file */116 __POSIX_DEF__(ino_t)st_ino; /* inode number */117 __POSIX_DEF__(mode_t)st_mode; /* protection */118 __POSIX_DEF__(nlink_t)st_nlink; /* number of hard links */119 __POSIX_DEF__(uid_t)st_uid; /* user ID of owner */120 __POSIX_DEF__(gid_t)st_gid; /* group ID of owner */121 __POSIX_DEF__(dev_t)st_rdev; /* device ID (if special file) */122 __POSIX_DEF__(off_t)st_size; /* total size, in bytes */123 __POSIX_DEF__(blksize_t)st_blksize; /* blocksize for file system I/O */124 __POSIX_DEF__(blkcnt_t)st_blocks; /* number of 512B blocks allocated */110 struct stat { 111 dev_t st_dev; /* ID of device containing file */ 112 ino_t st_ino; /* inode number */ 113 mode_t st_mode; /* protection */ 114 nlink_t st_nlink; /* number of hard links */ 115 uid_t st_uid; /* user ID of owner */ 116 gid_t st_gid; /* group ID of owner */ 117 dev_t st_rdev; /* device ID (if special file) */ 118 off_t st_size; /* total size, in bytes */ 119 blksize_t st_blksize; /* blocksize for file system I/O */ 120 blkcnt_t st_blocks; /* number of 512B blocks allocated */ 125 121 time_t st_atime; /* time of last access */ 126 122 time_t st_mtime; /* time of last modification */ … … 128 124 }; 129 125 130 extern int __POSIX_DEF__(fstat)(int fd, struct __POSIX_DEF__(stat)*st);131 extern int __POSIX_DEF__(lstat)(const char *__restrict__ path, struct __POSIX_DEF__(stat)*__restrict__ st);132 extern int __POSIX_DEF__(stat)(const char *__restrict__ path, struct __POSIX_DEF__(stat)*__restrict__ st);133 extern int __POSIX_DEF__(chmod)(const char *path, __POSIX_DEF__(mode_t)mode);134 extern __POSIX_DEF__(mode_t) __POSIX_DEF__(umask)(__POSIX_DEF__(mode_t)mask);135 extern int __POSIX_DEF__(mkdir)(const char *path, __POSIX_DEF__(mode_t)mode);126 extern int fstat(int fd, struct stat *st); 127 extern int lstat(const char *__restrict__ path, struct stat *__restrict__ st); 128 extern int stat(const char *__restrict__ path, struct stat *__restrict__ st); 129 extern int chmod(const char *path, mode_t mode); 130 extern mode_t umask(mode_t mask); 131 extern int mkdir(const char *path, mode_t mode); 136 132 137 133 -
uspace/lib/posix/include/posix/sys/time.h
re0f47f5 r7f9df7b9 34 34 #define POSIX_SYS_TIME_H_ 35 35 36 #ifndef __POSIX_DEF__37 #define __POSIX_DEF__(x) x38 #endif39 40 36 #include "libc/sys/time.h" 41 37 -
uspace/lib/posix/include/posix/sys/types.h
re0f47f5 r7f9df7b9 37 37 #define POSIX_SYS_TYPES_H_ 38 38 39 #ifndef __POSIX_DEF__40 #define __POSIX_DEF__(x) x41 #endif42 43 39 #include "libc/offset.h" 44 40 #include "libc/sys/time.h" 45 41 #include "libc/types/common.h" 46 42 47 typedef unsigned int __POSIX_DEF__(ino_t);48 typedef unsigned int __POSIX_DEF__(nlink_t);49 typedef unsigned int __POSIX_DEF__(uid_t);50 typedef unsigned int __POSIX_DEF__(gid_t);51 typedef off64_t __POSIX_DEF__(off_t);52 typedef long __POSIX_DEF__(blksize_t);53 typedef long __POSIX_DEF__(blkcnt_t);54 typedef int64_t __POSIX_DEF__(pid_t);55 typedef sysarg_t __POSIX_DEF__(dev_t);56 typedef unsigned int __POSIX_DEF__(mode_t);43 typedef unsigned int ino_t; 44 typedef unsigned int nlink_t; 45 typedef unsigned int uid_t; 46 typedef unsigned int gid_t; 47 typedef off64_t off_t; 48 typedef long blksize_t; 49 typedef long blkcnt_t; 50 typedef int64_t pid_t; 51 typedef sysarg_t dev_t; 52 typedef unsigned int mode_t; 57 53 58 54 /* PThread Types */ 59 typedef struct __POSIX_DEF__(thread_attr) __POSIX_DEF__(thread_attr_t);55 typedef struct thread_attr thread_attr_t; 60 56 61 57 /* Clock Types */ 62 typedef long __POSIX_DEF__(clock_t);63 typedef int __POSIX_DEF__(clockid_t);58 typedef long clock_t; 59 typedef int clockid_t; 64 60 65 61 -
uspace/lib/posix/include/posix/sys/wait.h
re0f47f5 r7f9df7b9 36 36 #define POSIX_SYS_WAIT_H_ 37 37 38 #ifndef __POSIX_DEF__39 #define __POSIX_DEF__(x) x40 #endif41 42 38 #include "types.h" 43 39 … … 56 52 extern int __posix_wtermsig(int status); 57 53 58 extern __POSIX_DEF__(pid_t) __POSIX_DEF__(wait)(int *stat_ptr);59 extern __POSIX_DEF__(pid_t) __POSIX_DEF__(waitpid)(__POSIX_DEF__(pid_t)pid, int *stat_ptr, int options);54 extern pid_t wait(int *stat_ptr); 55 extern pid_t waitpid(pid_t pid, int *stat_ptr, int options); 60 56 61 57 -
uspace/lib/posix/include/posix/time.h
re0f47f5 r7f9df7b9 37 37 #define POSIX_TIME_H_ 38 38 39 #ifndef __POSIX_DEF__40 #define __POSIX_DEF__(x) x41 #endif42 43 39 #include "sys/types.h" 44 40 … … 51 47 #ifndef __locale_t_defined 52 48 #define __locale_t_defined 53 typedef struct __posix_locale * __POSIX_DEF__(locale_t);49 typedef struct __posix_locale *locale_t; 54 50 #ifndef LIBPOSIX_INTERNAL 55 #define locale_t __POSIX_DEF__(locale_t)51 #define locale_t locale_t 56 52 #endif 57 53 #endif 58 54 59 55 #ifndef POSIX_SIGNAL_H_ 60 struct __POSIX_DEF__(sigevent);56 struct sigevent; 61 57 #ifndef LIBPOSIX_INTERNAL 62 #define sigevent __POSIX_DEF__(sigevent)58 #define sigevent sigevent 63 59 #endif 64 60 #endif 65 61 66 62 #undef CLOCK_REALTIME 67 #define CLOCK_REALTIME (( __POSIX_DEF__(clockid_t)) 0)63 #define CLOCK_REALTIME ((clockid_t) 0) 68 64 69 struct __POSIX_DEF__(timespec){65 struct timespec { 70 66 time_t tv_sec; /* Seconds. */ 71 67 long tv_nsec; /* Nanoseconds. */ 72 68 }; 73 69 74 struct __POSIX_DEF__(itimerspec){75 struct __POSIX_DEF__(timespec)it_interval; /* Timer period. */76 struct __POSIX_DEF__(timespec)it_value; /* Timer expiration. */70 struct itimerspec { 71 struct timespec it_interval; /* Timer period. */ 72 struct timespec it_value; /* Timer expiration. */ 77 73 }; 78 74 79 typedef struct __posix_timer * __POSIX_DEF__(timer_t);75 typedef struct __posix_timer *timer_t; 80 76 81 77 /* Timezones */ 82 extern int __POSIX_DEF__(daylight);83 extern long __POSIX_DEF__(timezone);84 extern char * __POSIX_DEF__(tzname)[2];85 extern void __POSIX_DEF__(tzset)(void);78 extern int daylight; 79 extern long timezone; 80 extern char *tzname[2]; 81 extern void tzset(void); 86 82 87 83 /* Time */ 88 extern time_t __POSIX_DEF__(time)(time_t *t);84 extern time_t time(time_t *t); 89 85 90 86 /* Broken-down Time */ 91 extern struct tm * __POSIX_DEF__(gmtime_r)(const time_t *__restrict__ timer,87 extern struct tm *gmtime_r(const time_t *__restrict__ timer, 92 88 struct tm *__restrict__ result); 93 extern struct tm * __POSIX_DEF__(gmtime)(const time_t *__restrict__ timep);94 extern struct tm * __POSIX_DEF__(localtime_r)(const time_t *__restrict__ timer,89 extern struct tm *gmtime(const time_t *__restrict__ timep); 90 extern struct tm *localtime_r(const time_t *__restrict__ timer, 95 91 struct tm *__restrict__ result); 96 extern struct tm * __POSIX_DEF__(localtime)(const time_t *__restrict__ timep);92 extern struct tm *localtime(const time_t *__restrict__ timep); 97 93 98 94 /* Formatting Calendar Time */ 99 extern char * __POSIX_DEF__(asctime_r)(const struct tm *__restrict__ timeptr,95 extern char *asctime_r(const struct tm *__restrict__ timeptr, 100 96 char *__restrict__ buf); 101 extern char * __POSIX_DEF__(asctime)(const struct tm *__restrict__ timeptr);102 extern char * __POSIX_DEF__(ctime_r)(const time_t *timer, char *buf);103 extern char * __POSIX_DEF__(ctime)(const time_t *timer);97 extern char *asctime(const struct tm *__restrict__ timeptr); 98 extern char *ctime_r(const time_t *timer, char *buf); 99 extern char *ctime(const time_t *timer); 104 100 extern time_t time(time_t *t); 105 101 106 102 /* Clocks */ 107 extern int __POSIX_DEF__(clock_getres)(__POSIX_DEF__(clockid_t)clock_id,108 struct __POSIX_DEF__(timespec)*res);109 extern int __POSIX_DEF__(clock_gettime)(__POSIX_DEF__(clockid_t)clock_id,110 struct __POSIX_DEF__(timespec)*tp);111 extern int __POSIX_DEF__(clock_settime)(__POSIX_DEF__(clockid_t)clock_id,112 const struct __POSIX_DEF__(timespec) *tp);113 extern int __POSIX_DEF__(clock_nanosleep)(__POSIX_DEF__(clockid_t)clock_id, int flags,114 const struct __POSIX_DEF__(timespec) *rqtp, struct __POSIX_DEF__(timespec)*rmtp);103 extern int clock_getres(clockid_t clock_id, 104 struct timespec *res); 105 extern int clock_gettime(clockid_t clock_id, 106 struct timespec *tp); 107 extern int clock_settime(clockid_t clock_id, 108 const struct timespec *tp); 109 extern int clock_nanosleep(clockid_t clock_id, int flags, 110 const struct timespec *rqtp, struct timespec *rmtp); 115 111 116 112 /* CPU Time */ 117 extern __POSIX_DEF__(clock_t) __POSIX_DEF__(clock)(void);113 extern clock_t clock(void); 118 114 119 115 -
uspace/lib/posix/include/posix/ucontext.h
re0f47f5 r7f9df7b9 36 36 #define POSIX_UCONTEXT_H_ 37 37 38 #ifndef __POSIX_DEF__39 #define __POSIX_DEF__(x) x40 #endif41 42 38 #include "sys/types.h" 43 39 44 typedef int __POSIX_DEF__(sig_atomic_t);45 typedef uint32_t __POSIX_DEF__(sigset_t);46 typedef struct __POSIX_DEF__(mcontext){40 typedef int sig_atomic_t; 41 typedef uint32_t sigset_t; 42 typedef struct mcontext { 47 43 /* must not be empty to avoid compiler warnings (-pedantic) */ 48 44 int dummy; 49 } __POSIX_DEF__(mcontext_t);45 } mcontext_t; 50 46 51 union __POSIX_DEF__(sigval){47 union sigval { 52 48 int sival_int; 53 49 void *sival_ptr; 54 50 }; 55 51 56 struct __POSIX_DEF__(sigevent){52 struct sigevent { 57 53 int sigev_notify; /* Notification type. */ 58 54 int sigev_signo; /* Signal number. */ 59 union __POSIX_DEF__(sigval)sigev_value; /* Signal value. */60 void (*sigev_notify_function)(union __POSIX_DEF__(sigval)); /* Notification function. */61 __POSIX_DEF__(thread_attr_t)*sigev_notify_attributes; /* Notification attributes. */55 union sigval sigev_value; /* Signal value. */ 56 void (*sigev_notify_function)(union sigval); /* Notification function. */ 57 thread_attr_t *sigev_notify_attributes; /* Notification attributes. */ 62 58 }; 63 59 … … 66 62 size_t ss_size; 67 63 int ss_flags; 68 } __POSIX_DEF__(stack_t);64 } stack_t; 69 65 70 typedef struct __POSIX_DEF__(ucontext){71 struct __POSIX_DEF__(ucontext)*uc_link;72 __POSIX_DEF__(sigset_t)uc_sigmask;73 __POSIX_DEF__(stack_t)uc_stack;74 __POSIX_DEF__(mcontext_t)uc_mcontext;75 } __POSIX_DEF__(ucontext_t);66 typedef struct ucontext { 67 struct ucontext *uc_link; 68 sigset_t uc_sigmask; 69 stack_t uc_stack; 70 mcontext_t uc_mcontext; 71 } ucontext_t; 76 72 77 73 -
uspace/lib/posix/include/posix/unistd.h
re0f47f5 r7f9df7b9 37 37 #define POSIX_UNISTD_H_ 38 38 39 #ifndef __POSIX_DEF__40 #define __POSIX_DEF__(x) x41 #endif42 43 39 #include "sys/types.h" 44 40 #include "stddef.h" … … 51 47 #define _exit exit 52 48 53 extern char * __POSIX_DEF__(optarg);49 extern char *optarg; 54 50 extern int optind, opterr, optopt; 55 extern int __POSIX_DEF__(getopt)(int, char * const [], const char *);51 extern int getopt(int, char * const [], const char *); 56 52 57 53 /* Environment */ 58 extern char ** __POSIX_DEF__(environ);54 extern char **environ; 59 55 60 56 /* Sleeping */ 61 extern unsigned int __POSIX_DEF__(sleep)(unsigned int);57 extern unsigned int sleep(unsigned int); 62 58 63 59 /* Login Information */ 64 extern char * __POSIX_DEF__(getlogin)(void);65 extern int __POSIX_DEF__(getlogin_r)(char *name, size_t namesize);60 extern char *getlogin(void); 61 extern int getlogin_r(char *name, size_t namesize); 66 62 67 63 /* Identifying Terminals */ 68 extern int __POSIX_DEF__(isatty)(int fd);64 extern int isatty(int fd); 69 65 70 66 /* Working Directory */ 71 extern char * __POSIX_DEF__(getcwd)(char *buf, size_t size);72 extern int __POSIX_DEF__(chdir)(const char *path);67 extern char *getcwd(char *buf, size_t size); 68 extern int chdir(const char *path); 73 69 74 70 /* Query Memory Parameters */ 75 extern int __POSIX_DEF__(getpagesize)(void);71 extern int getpagesize(void); 76 72 77 73 /* Process Identification */ 78 extern __POSIX_DEF__(pid_t) __POSIX_DEF__(getpid)(void);79 extern __POSIX_DEF__(uid_t) __POSIX_DEF__(getuid)(void);80 extern __POSIX_DEF__(gid_t) __POSIX_DEF__(getgid)(void);74 extern pid_t getpid(void); 75 extern uid_t getuid(void); 76 extern gid_t getgid(void); 81 77 82 78 /* File Manipulation */ 83 extern int __POSIX_DEF__(close)(int fildes);84 extern ssize_t __POSIX_DEF__(read)(int fildes, void *buf, size_t nbyte);85 extern ssize_t __POSIX_DEF__(write)(int fildes, const void *buf, size_t nbyte);86 extern __POSIX_DEF__(off_t) __POSIX_DEF__(lseek)(int fildes,87 __POSIX_DEF__(off_t)offset, int whence);88 extern int __POSIX_DEF__(fsync)(int fildes);89 extern int __POSIX_DEF__(ftruncate)(int fildes, __POSIX_DEF__(off_t)length);90 extern int __POSIX_DEF__(rmdir)(const char *path);91 extern int __POSIX_DEF__(unlink)(const char *path);92 extern int __POSIX_DEF__(dup)(int fildes);93 extern int __POSIX_DEF__(dup2)(int fildes, int fildes2);79 extern int close(int fildes); 80 extern ssize_t read(int fildes, void *buf, size_t nbyte); 81 extern ssize_t write(int fildes, const void *buf, size_t nbyte); 82 extern off_t lseek(int fildes, 83 off_t offset, int whence); 84 extern int fsync(int fildes); 85 extern int ftruncate(int fildes, off_t length); 86 extern int rmdir(const char *path); 87 extern int unlink(const char *path); 88 extern int dup(int fildes); 89 extern int dup2(int fildes, int fildes2); 94 90 95 91 /* Standard Streams */ … … 110 106 #define W_OK 2 /* Test for write permission. */ 111 107 #define R_OK 4 /* Test for read permission. */ 112 extern int __POSIX_DEF__(access)(const char *path, int amode);108 extern int access(const char *path, int amode); 113 109 114 110 /* System Parameters */ … … 119 115 _SC_CLK_TCK 120 116 }; 121 extern long __POSIX_DEF__(sysconf)(int name);117 extern long sysconf(int name); 122 118 123 119 /* Path Configuration Parameters */ … … 143 139 _PC_VDISABLE 144 140 }; 145 extern long __POSIX_DEF__(pathconf)(const char *path, int name);141 extern long pathconf(const char *path, int name); 146 142 147 143 /* Creating a Process */ 148 extern __POSIX_DEF__(pid_t) __POSIX_DEF__(fork)(void);144 extern pid_t fork(void); 149 145 150 146 /* Executing a File */ 151 extern int __POSIX_DEF__(execv)(const char *path, char *const argv[]);152 extern int __POSIX_DEF__(execvp)(const char *file, char *const argv[]);147 extern int execv(const char *path, char *const argv[]); 148 extern int execvp(const char *file, char *const argv[]); 153 149 154 150 /* Creating a Pipe */ 155 extern int __POSIX_DEF__(pipe)(int fildes[2]);151 extern int pipe(int fildes[2]); 156 152 157 153 /* Issue alarm signal. */ 158 extern unsigned int __POSIX_DEF__(alarm)(unsigned int);154 extern unsigned int alarm(unsigned int); 159 155 160 156 #endif /* POSIX_UNISTD_H_ */ -
uspace/lib/posix/src/dlfcn.c
re0f47f5 r7f9df7b9 31 31 */ 32 32 33 #define LIBPOSIX_INTERNAL34 #define __POSIX_DEF__(x) posix_##x35 36 33 #include "internal/common.h" 37 34 #include "posix/dlfcn.h" 38 35 39 #include "libc/dlfcn.h" 36 _HIDE_LIBC_SYMBOL(dlopen) 37 extern void *__helenos_libc_dlopen(const char *filename, int flags); 40 38 41 void * posix_dlopen(const char *filename, int flags)39 void *dlopen(const char *filename, int flags) 42 40 { 43 41 if (flags != 0) { … … 45 43 } 46 44 47 return dlopen(filename, 0);45 return __helenos_libc_dlopen(filename, 0); 48 46 } 49 47 50 void *posix_dlsym(void *handle, const char *symbol) 51 { 52 return dlsym(handle, symbol); 53 } 54 55 int posix_dlclose(void *handle) 48 int dlclose(void *handle) 56 49 { 57 50 not_implemented(); … … 59 52 } 60 53 61 char * posix_dlerror(void)54 char *dlerror(void) 62 55 { 63 56 not_implemented(); -
uspace/lib/posix/src/fcntl.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "internal/common.h" 39 36 #include "posix/fcntl.h" … … 51 48 * to the requested operation. 52 49 */ 53 int posix_fcntl(int fd, int cmd, ...)50 int fcntl(int fd, int cmd, ...) 54 51 { 55 52 int flags; … … 102 99 * @param posix_flags Access mode flags. 103 100 */ 104 int posix_open(const char *pathname, int posix_flags, ...)101 int open(const char *pathname, int posix_flags, ...) 105 102 { 106 posix_mode_t posix_mode = 0;103 mode_t posix_mode = 0; 107 104 if (posix_flags & O_CREAT) { 108 105 va_list args; 109 106 va_start(args, posix_flags); 110 posix_mode = va_arg(args, posix_mode_t);107 posix_mode = va_arg(args, mode_t); 111 108 va_end(args); 112 109 (void) posix_mode; -
uspace/lib/posix/src/fnmatch.c
re0f47f5 r7f9df7b9 41 41 * will be fairly straightforward. 42 42 */ 43 44 #define LIBPOSIX_INTERNAL45 #define __POSIX_DEF__(x) posix_##x46 43 47 44 #include "libc/stdbool.h" … … 205 202 { 206 203 const struct _char_class *class = elem; 207 return posix_strcmp((const char *) key, class->name);204 return strcmp((const char *) key, class->name); 208 205 } 209 206 … … 218 215 { 219 216 /* Search for class in the array of supported character classes. */ 220 const struct _char_class *class = posix_bsearch(cname, _char_classes,217 const struct _char_class *class = bsearch(cname, _char_classes, 221 218 sizeof(_char_classes) / sizeof(struct _char_class), 222 219 sizeof(struct _char_class), _class_compare); … … 582 579 { 583 580 assert(s != NULL); 584 char *result = posix_strdup(s);581 char *result = strdup(s); 585 582 for (char *i = result; *i != '\0'; ++i) { 586 583 *i = tolower(*i); … … 598 595 * @return Zero if the string matches the pattern, FNM_NOMATCH otherwise. 599 596 */ 600 int posix_fnmatch(const char *pattern, const char *string, int flags)597 int fnmatch(const char *pattern, const char *string, int flags) 601 598 { 602 599 assert(pattern != NULL); … … 637 634 #undef assert 638 635 #define assert(x) { if (x) printf("SUCCESS: "#x"\n"); else { printf("FAILED: "#x"\n"); fail++; } } 639 #define match(s1, s2, flags) assert( posix_fnmatch(s1, s2, flags) == 0)640 #define nomatch(s1, s2, flags) assert( posix_fnmatch(s1, s2, flags) == FNM_NOMATCH)636 #define match(s1, s2, flags) assert(fnmatch(s1, s2, flags) == 0) 637 #define nomatch(s1, s2, flags) assert(fnmatch(s1, s2, flags) == FNM_NOMATCH) 641 638 642 639 static_assert(FNM_PATHNAME == FNM_FILE_NAME); -
uspace/lib/posix/src/internal/common.h
re0f47f5 r7f9df7b9 50 50 } while (0) 51 51 52 // Just a marker for external tools. 53 #define _HIDE_LIBC_SYMBOL(symbol) 54 52 55 /* Checks if the value is a failing error code. 53 56 * If so, writes the error code to errno and returns true. -
uspace/lib/posix/src/locale.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "internal/common.h" 39 36 #include "posix/locale.h" … … 54 51 }; 55 52 56 const struct posix_lconv C_LOCALE = {53 const struct lconv C_LOCALE = { 57 54 .currency_symbol = (char *) "", 58 55 .decimal_point = (char *) ".", … … 88 85 * @return Original locale name on success, NULL on failure. 89 86 */ 90 char * posix_setlocale(int category, const char *locale)87 char *setlocale(int category, const char *locale) 91 88 { 92 89 // TODO 93 90 if (locale == NULL || *locale == '\0' || 94 posix_strcmp(locale, "C") == 0) {91 strcmp(locale, "C") == 0) { 95 92 return (char *) "C"; 96 93 } … … 103 100 * @return Information about the current locale. 104 101 */ 105 struct posix_lconv *posix_localeconv(void)102 struct lconv *localeconv(void) 106 103 { 107 104 // TODO 108 return (struct posix_lconv *) &C_LOCALE;105 return (struct lconv *) &C_LOCALE; 109 106 } 110 107 … … 115 112 * @return Duplicated object. 116 113 */ 117 posix_locale_t posix_duplocale(posix_locale_t locobj)114 locale_t duplocale(locale_t locobj) 118 115 { 119 116 if (locobj == NULL) { … … 121 118 return NULL; 122 119 } 123 posix_locale_t copy = malloc(sizeof(struct __posix_locale));120 locale_t copy = malloc(sizeof(struct __posix_locale)); 124 121 if (copy == NULL) { 125 122 errno = ENOMEM; … … 135 132 * @param locobj Object to free. 136 133 */ 137 void posix_freelocale(posix_locale_t locobj)134 void freelocale(locale_t locobj) 138 135 { 139 136 if (locobj) { … … 150 147 * @return The new/modified locale object. 151 148 */ 152 posix_locale_t posix_newlocale(int category_mask, const char *locale,153 posix_locale_t base)149 locale_t newlocale(int category_mask, const char *locale, 150 locale_t base) 154 151 { 155 152 if (locale == NULL || … … 159 156 } 160 157 // TODO 161 posix_locale_t new = malloc(sizeof(struct __posix_locale));158 locale_t new = malloc(sizeof(struct __posix_locale)); 162 159 if (new == NULL) { 163 160 errno = ENOMEM; … … 165 162 } 166 163 if (base != NULL) { 167 posix_freelocale(base);164 freelocale(base); 168 165 } 169 166 return new; … … 176 173 * @return The previously set locale or LC_GLOBAL_LOCALE 177 174 */ 178 posix_locale_t posix_uselocale(posix_locale_t newloc)175 locale_t uselocale(locale_t newloc) 179 176 { 180 177 // TODO -
uspace/lib/posix/src/pthread/condvar.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "posix/pthread.h" 39 36 #include "errno.h" … … 66 63 67 64 int pthread_cond_timedwait(pthread_cond_t *restrict condvar, 68 pthread_mutex_t *restrict mutex, const struct __POSIX_DEF__(timespec)*restrict timeout)65 pthread_mutex_t *restrict mutex, const struct timespec *restrict timeout) 69 66 { 70 67 not_implemented(); -
uspace/lib/posix/src/pthread/keys.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "posix/stdlib.h" 39 36 #include "posix/pthread.h" -
uspace/lib/posix/src/pthread/mutex.c
re0f47f5 r7f9df7b9 32 32 /** @file Pthread: mutexes. 33 33 */ 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 34 38 35 #include "posix/pthread.h" -
uspace/lib/posix/src/pthread/threads.c
re0f47f5 r7f9df7b9 32 32 /** @file Pthread: thread management. 33 33 */ 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 34 38 35 #include "posix/pthread.h" -
uspace/lib/posix/src/pwd.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "libc/stdbool.h" 39 36 #include "posix/pwd.h" … … 45 42 46 43 /* dummy user account */ 47 static const struct p osix_passwd dummy_pwd = {44 static const struct passwd dummy_pwd = { 48 45 .pw_name = (char *) "user", 49 46 .pw_uid = 0, … … 62 59 * doesn't have user accounts, this always returns the same made-up entry. 63 60 */ 64 struct p osix_passwd *posix_getpwent(void)61 struct passwd *getpwent(void) 65 62 { 66 63 if (entry_read) { … … 69 66 70 67 entry_read = true; 71 return (struct p osix_passwd *) &dummy_pwd;68 return (struct passwd *) &dummy_pwd; 72 69 } 73 70 … … 75 72 * Rewind the user list. 76 73 */ 77 void posix_setpwent(void)74 void setpwent(void) 78 75 { 79 76 entry_read = false; … … 83 80 * Ends enumerating and releases all resources. (Noop) 84 81 */ 85 void posix_endpwent(void)82 void endpwent(void) 86 83 { 87 84 /* noop */ … … 94 91 * @return Either found entry or NULL if no such entry exists. 95 92 */ 96 struct p osix_passwd *posix_getpwnam(const char *name)93 struct passwd *getpwnam(const char *name) 97 94 { 98 95 assert(name != NULL); 99 96 100 if ( posix_strcmp(name, "user") != 0) {97 if (strcmp(name, "user") != 0) { 101 98 return NULL; 102 99 } 103 100 104 return (struct p osix_passwd *) &dummy_pwd;101 return (struct passwd *) &dummy_pwd; 105 102 } 106 103 … … 116 113 * non-zero error number if error occured. 117 114 */ 118 int posix_getpwnam_r(const char *name, struct posix_passwd *pwd,119 char *buffer, size_t bufsize, struct p osix_passwd **result)115 int getpwnam_r(const char *name, struct passwd *pwd, 116 char *buffer, size_t bufsize, struct passwd **result) 120 117 { 121 118 assert(name != NULL); … … 124 121 assert(result != NULL); 125 122 126 if ( posix_strcmp(name, "user") != 0) {123 if (strcmp(name, "user") != 0) { 127 124 *result = NULL; 128 125 return 0; 129 126 } 130 127 131 return posix_getpwuid_r(0, pwd, buffer, bufsize, result);128 return getpwuid_r(0, pwd, buffer, bufsize, result); 132 129 } 133 130 … … 138 135 * @return Either found entry or NULL if no such entry exists. 139 136 */ 140 struct p osix_passwd *posix_getpwuid(posix_uid_t uid)137 struct passwd *getpwuid(uid_t uid) 141 138 { 142 139 if (uid != 0) { … … 144 141 } 145 142 146 return (struct p osix_passwd *) &dummy_pwd;143 return (struct passwd *) &dummy_pwd; 147 144 } 148 145 … … 158 155 * non-zero error number if error occured. 159 156 */ 160 int posix_getpwuid_r(posix_uid_t uid, struct posix_passwd *pwd,161 char *buffer, size_t bufsize, struct p osix_passwd **result)157 int getpwuid_r(uid_t uid, struct passwd *pwd, 158 char *buffer, size_t bufsize, struct passwd **result) 162 159 { 163 160 assert(pwd != NULL); … … 184 181 pwd->pw_dir = (char *) bf + 5; 185 182 pwd->pw_shell = (char *) bf + 7; 186 *result = (struct p osix_passwd *) pwd;183 *result = (struct passwd *) pwd; 187 184 188 185 return 0; -
uspace/lib/posix/src/signal.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "posix/signal.h" 39 36 #include "internal/common.h" … … 61 58 static LIST_INITIALIZE(_signal_queue); 62 59 63 static posix_sigset_t _signal_mask = 0;60 static sigset_t _signal_mask = 0; 64 61 65 62 #define DEFAULT_HANDLER { .sa_handler = SIG_DFL, \ … … 67 64 68 65 /* Actions associated with each signal number. */ 69 static struct posix_sigaction _signal_actions[_TOP_SIGNAL + 1] = {66 static struct sigaction _signal_actions[_TOP_SIGNAL + 1] = { 70 67 DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 71 68 DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, … … 111 108 case SIGILL: 112 109 case SIGSEGV: 113 p osix_psignal(signo, "Hardware exception raised by user code");110 psignal(signo, "Hardware exception raised by user code"); 114 111 abort(); 115 112 case SIGSYS: … … 124 121 case SIGTTIN: 125 122 case SIGTTOU: 126 p osix_psignal(signo, "Unsupported signal caught");123 psignal(signo, "Unsupported signal caught"); 127 124 abort(); 128 125 case SIGCHLD: … … 164 161 * @return Always returns zero. 165 162 */ 166 int posix_sigemptyset(posix_sigset_t *set)163 int sigemptyset(sigset_t *set) 167 164 { 168 165 assert(set != NULL); … … 178 175 * @return Always returns zero. 179 176 */ 180 int posix_sigfillset(posix_sigset_t *set)177 int sigfillset(sigset_t *set) 181 178 { 182 179 assert(set != NULL); … … 193 190 * @return Always returns zero. 194 191 */ 195 int posix_sigaddset(posix_sigset_t *set, int signo)192 int sigaddset(sigset_t *set, int signo) 196 193 { 197 194 assert(set != NULL); … … 208 205 * @return Always returns zero. 209 206 */ 210 int posix_sigdelset(posix_sigset_t *set, int signo)207 int sigdelset(sigset_t *set, int signo) 211 208 { 212 209 assert(set != NULL); … … 223 220 * @return 1 if the signal is in the set, 0 otherwise. 224 221 */ 225 int posix_sigismember(const posix_sigset_t *set, int signo)222 int sigismember(const sigset_t *set, int signo) 226 223 { 227 224 assert(set != NULL); … … 239 236 * @param oact 240 237 */ 241 static void _sigaction_unsafe(int sig, const struct posix_sigaction *restrict act,242 struct posix_sigaction *restrict oact)238 static void _sigaction_unsafe(int sig, const struct sigaction *restrict act, 239 struct sigaction *restrict oact) 243 240 { 244 241 if (oact != NULL) { 245 242 memcpy(oact, &_signal_actions[sig], 246 sizeof(struct posix_sigaction));243 sizeof(struct sigaction)); 247 244 } 248 245 249 246 if (act != NULL) { 250 247 memcpy(&_signal_actions[sig], act, 251 sizeof(struct posix_sigaction));248 sizeof(struct sigaction)); 252 249 } 253 250 } … … 263 260 * @return -1 with errno set on failure, 0 on success. 264 261 */ 265 int posix_sigaction(int sig, const struct posix_sigaction *restrict act,266 struct posix_sigaction *restrict oact)262 int sigaction(int sig, const struct sigaction *restrict act, 263 struct sigaction *restrict oact) 267 264 { 268 265 if (sig > _TOP_SIGNAL || (act != NULL && … … 273 270 274 271 if (sig > _TOP_CATCHABLE_SIGNAL) { 275 p osix_psignal(sig,272 psignal(sig, 276 273 "WARNING: registering handler for a partially" 277 274 " or fully unsupported signal. This handler may only be" … … 294 291 * @return SIG_ERR on failure, original handler on success. 295 292 */ 296 void (* posix_signal(int sig, void (*func)(int)))(int)297 { 298 struct posix_sigaction new = {293 void (*signal(int sig, void (*func)(int)))(int) 294 { 295 struct sigaction new = { 299 296 .sa_handler = func, 300 297 .sa_mask = 0, … … 302 299 .sa_sigaction = NULL 303 300 }; 304 struct posix_sigaction old;305 if ( posix_sigaction(sig, func == NULL ? NULL : &new, &old) == 0) {301 struct sigaction old; 302 if (sigaction(sig, func == NULL ? NULL : &new, &old) == 0) { 306 303 return old.sa_handler; 307 304 } else { … … 313 310 link_t link; 314 311 int signo; 315 posix_siginfo_t siginfo;312 siginfo_t siginfo; 316 313 } signal_queue_item; 317 314 … … 322 319 * @param siginfo Additional information about the signal. 323 320 */ 324 static void _queue_signal(int signo, posix_siginfo_t *siginfo)321 static void _queue_signal(int signo, siginfo_t *siginfo) 325 322 { 326 323 assert(signo >= 0 && signo <= _TOP_SIGNAL); … … 330 327 link_initialize(&(item->link)); 331 328 item->signo = signo; 332 memcpy(&item->siginfo, siginfo, sizeof( posix_siginfo_t));329 memcpy(&item->siginfo, siginfo, sizeof(siginfo_t)); 333 330 list_append(&(item->link), &_signal_queue); 334 331 } … … 343 340 * blocked. 344 341 */ 345 static int _raise_sigaction(int signo, posix_siginfo_t *siginfo)342 static int _raise_sigaction(int signo, siginfo_t *siginfo) 346 343 { 347 344 assert(signo >= 0 && signo <= _TOP_SIGNAL); … … 350 347 fibril_mutex_lock(&_signal_mutex); 351 348 352 struct posix_sigaction action = _signal_actions[signo];353 354 if ( posix_sigismember(&_signal_mask, signo) ||349 struct sigaction action = _signal_actions[signo]; 350 351 if (sigismember(&_signal_mask, signo) || 355 352 action.sa_handler == SIG_HOLD) { 356 353 _queue_signal(signo, siginfo); … … 364 361 365 362 if ((action.sa_flags & SA_RESETHAND) && signo != SIGILL && signo != SIGTRAP) { 366 _signal_actions[signo] = (struct posix_sigaction) DEFAULT_HANDLER;363 _signal_actions[signo] = (struct sigaction) DEFAULT_HANDLER; 367 364 } 368 365 … … 394 391 list_get_instance(iterator, signal_queue_item, link); 395 392 396 if (! posix_sigismember(&_signal_mask, item->signo) &&393 if (!sigismember(&_signal_mask, item->signo) && 397 394 _signal_actions[item->signo].sa_handler != SIG_HOLD) { 398 395 list_remove(&(item->link)); … … 411 408 * @return -1 with errno set on failure, 0 on success. 412 409 */ 413 int posix_raise(int sig)410 int raise(int sig) 414 411 { 415 412 if (sig >= 0 && sig <= _TOP_SIGNAL) { 416 posix_siginfo_t siginfo = {413 siginfo_t siginfo = { 417 414 .si_signo = sig, 418 415 .si_code = SI_USER … … 433 430 * action, invalid signal number, lack of permissions, etc.), 0 on success. 434 431 */ 435 int posix_kill(posix_pid_t pid, int signo)432 int kill(pid_t pid, int signo) 436 433 { 437 434 if (pid < 1) { … … 446 443 } 447 444 448 if (pid == (p osix_pid_t) task_get_id()) {449 return posix_raise(signo);445 if (pid == (pid_t) task_get_id()) { 446 return raise(signo); 450 447 } 451 448 … … 471 468 * @return -1 on failure, 0 on success (see kill()). 472 469 */ 473 int posix_killpg(posix_pid_t pid, int sig)470 int killpg(pid_t pid, int sig) 474 471 { 475 472 assert(pid > 1); 476 return posix_kill(-pid, sig);473 return kill(-pid, sig); 477 474 } 478 475 … … 483 480 * @param message String to output alongside human-readable signal description. 484 481 */ 485 void p osix_psiginfo(const posix_siginfo_t *pinfo, const char *message)482 void psiginfo(const siginfo_t *pinfo, const char *message) 486 483 { 487 484 assert(pinfo != NULL); 488 p osix_psignal(pinfo->si_signo, message);485 psignal(pinfo->si_signo, message); 489 486 // TODO: print si_code 490 487 } … … 496 493 * @param message String to output alongside human-readable signal description. 497 494 */ 498 void p osix_psignal(int signum, const char *message)499 { 500 char *sigmsg = posix_strsignal(signum);495 void psignal(int signum, const char *message) 496 { 497 char *sigmsg = strsignal(signum); 501 498 if (message == NULL || *message == '\0') { 502 499 fprintf(stderr, "%s\n", sigmsg); … … 514 511 * @return 0 success, errorcode on failure. 515 512 */ 516 int posix_thread_sigmask(int how, const posix_sigset_t *restrict set,517 posix_sigset_t *restrict oset)513 int thread_sigmask(int how, const sigset_t *restrict set, 514 sigset_t *restrict oset) 518 515 { 519 516 fibril_mutex_lock(&_signal_mutex); … … 554 551 * @return 0 on success, -1 with errno set on failure. 555 552 */ 556 int posix_sigprocmask(int how, const posix_sigset_t *restrict set,557 posix_sigset_t *restrict oset)558 { 559 int result = posix_thread_sigmask(how, set, oset);553 int sigprocmask(int how, const sigset_t *restrict set, 554 sigset_t *restrict oset) 555 { 556 int result = thread_sigmask(how, set, oset); 560 557 if (result != 0) { 561 558 errno = result; -
uspace/lib/posix/src/stdio.c
re0f47f5 r7f9df7b9 34 34 */ 35 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 39 36 #include "internal/common.h" 40 37 #include "posix/stdio.h" … … 55 52 #include "libc/adt/list.h" 56 53 57 /** Clears the stream's error and end-of-file indicators.58 *59 * @param stream Stream whose indicators shall be cleared.60 */61 void posix_clearerr(FILE *stream)62 {63 clearerr(stream);64 }65 66 54 /** 67 55 * Generate a pathname for the controlling terminal. … … 70 58 * @return Either s or static location filled with the requested pathname. 71 59 */ 72 char * posix_ctermid(char *s)60 char *ctermid(char *s) 73 61 { 74 62 /* Currently always returns an error value (empty string). */ … … 83 71 s[0] = '\0'; 84 72 return s; 85 }86 87 /**88 * Put a string on the stream.89 *90 * @param s String to be written.91 * @param stream Output stream.92 * @return Non-negative on success, EOF on failure.93 */94 int posix_fputs(const char *restrict s, FILE *restrict stream)95 {96 return fputs(s, stream);97 }98 99 /**100 * Push byte back into input stream.101 *102 * @param c Byte to be pushed back.103 * @param stream Stream to where the byte shall be pushed.104 * @return Provided byte on success or EOF if not possible.105 */106 int posix_ungetc(int c, FILE *stream)107 {108 return ungetc(c, stream);109 73 } 110 74 … … 122 86 * or -1 on error (set in errno). 123 87 */ 124 ssize_t posix_getdelim(char **restrict lineptr, size_t *restrict n,88 ssize_t getdelim(char **restrict lineptr, size_t *restrict n, 125 89 int delimiter, FILE *restrict stream) 126 90 { … … 194 158 * or -1 on error (set in errno). 195 159 */ 196 ssize_t posix_getline(char **restrict lineptr, size_t *restrict n,160 ssize_t getline(char **restrict lineptr, size_t *restrict n, 197 161 FILE *restrict stream) 198 162 { 199 return posix_getdelim(lineptr, n, '\n', stream); 200 } 201 202 /** 203 * Reopen a file stream. 204 * 205 * @param filename Pathname of a file to be reopened or NULL for changing 206 * the mode of the stream. 207 * @param mode Mode to be used for reopening the file or changing current 208 * mode of the stream. 209 * @param stream Current stream associated with the opened file. 210 * @return On success, either a stream of the reopened file or the provided 211 * stream with a changed mode. NULL otherwise. 212 */ 213 FILE *posix_freopen(const char *restrict filename, 214 const char *restrict mode, FILE *restrict stream) 215 { 216 return freopen(filename, mode, stream); 163 return getdelim(lineptr, n, '\n', stream); 217 164 } 218 165 … … 222 169 * @param s Error message. 223 170 */ 224 void p osix_perror(const char *s)171 void perror(const char *s) 225 172 { 226 173 if (s == NULL || s[0] == '\0') { 227 fprintf(stderr, "%s\n", posix_strerror(errno));174 fprintf(stderr, "%s\n", strerror(errno)); 228 175 } else { 229 fprintf(stderr, "%s: %s\n", s, posix_strerror(errno));176 fprintf(stderr, "%s: %s\n", s, strerror(errno)); 230 177 } 231 178 } … … 237 184 * @return Zero on success, non-zero (with errno set) on failure 238 185 */ 239 int posix_fsetpos(FILE *stream, const posix_fpos_t *pos)186 int fsetpos(FILE *stream, const fpos_t *pos) 240 187 { 241 188 return fseek64(stream, pos->offset, SEEK_SET); … … 248 195 * @return Zero on success, non-zero (with errno set) on failure 249 196 */ 250 int posix_fgetpos(FILE *restrict stream, posix_fpos_t *restrict pos)197 int fgetpos(FILE *restrict stream, fpos_t *restrict pos) 251 198 { 252 199 off64_t ret = ftell64(stream); … … 267 214 * @return Zero on success, -1 otherwise. 268 215 */ 269 int posix_fseek(FILE *stream, long offset, int whence) 270 { 271 return fseek(stream, offset, whence); 272 } 273 274 /** 275 * Reposition a file-position indicator in a stream. 276 * 277 * @param stream Stream to seek in. 278 * @param offset Direction and amount of bytes to seek. 279 * @param whence From where to seek. 280 * @return Zero on success, -1 otherwise. 281 */ 282 int posix_fseeko(FILE *stream, posix_off_t offset, int whence) 216 int fseeko(FILE *stream, off_t offset, int whence) 283 217 { 284 218 return fseek64(stream, offset, whence); … … 291 225 * @return Current offset or -1 if not possible. 292 226 */ 293 long posix_ftell(FILE *stream) 294 { 295 return ftell(stream); 296 } 297 298 /** 299 * Discover current file offset in a stream. 300 * 301 * @param stream Stream for which the offset shall be retrieved. 302 * @return Current offset or -1 if not possible. 303 */ 304 posix_off_t posix_ftello(FILE *stream) 227 off_t ftello(FILE *stream) 305 228 { 306 229 return ftell64(stream); … … 308 231 309 232 /** 310 * Discard prefetched data or write unwritten data.311 *312 * @param stream Stream that shall be flushed.313 * @return Zero on success, EOF on failure.314 */315 int posix_fflush(FILE *stream)316 {317 return fflush(stream);318 }319 320 /**321 233 * Print formatted output to the opened file. 322 234 * … … 325 237 * @return Either the number of printed characters or negative value on error. 326 238 */ 327 int posix_dprintf(int fildes, const char *restrict format, ...)239 int dprintf(int fildes, const char *restrict format, ...) 328 240 { 329 241 va_list list; 330 242 va_start(list, format); 331 int result = posix_vdprintf(fildes, format, list);243 int result = vdprintf(fildes, format, list); 332 244 va_end(list); 333 245 return result; … … 392 304 * @return Either the number of printed characters or negative value on error. 393 305 */ 394 int posix_vdprintf(int fildes, const char *restrict format, va_list ap)306 int vdprintf(int fildes, const char *restrict format, va_list ap) 395 307 { 396 308 printf_spec_t spec = { … … 411 323 * negative value on error. 412 324 */ 413 int posix_sprintf(char *s, const char *restrict format, ...)325 int sprintf(char *s, const char *restrict format, ...) 414 326 { 415 327 va_list list; 416 328 va_start(list, format); 417 int result = posix_vsprintf(s, format, list);329 int result = vsprintf(s, format, list); 418 330 va_end(list); 419 331 return result; … … 429 341 * negative value on error. 430 342 */ 431 int posix_vsprintf(char *s, const char *restrict format, va_list ap)343 int vsprintf(char *s, const char *restrict format, va_list ap) 432 344 { 433 345 return vsnprintf(s, STR_NO_LIMIT, format, ap); … … 441 353 * @return The number of converted output items or EOF on failure. 442 354 */ 443 int posix_fscanf(FILE *restrict stream, const char *restrict format, ...)355 int fscanf(FILE *restrict stream, const char *restrict format, ...) 444 356 { 445 357 va_list list; 446 358 va_start(list, format); 447 int result = posix_vfscanf(stream, format, list);359 int result = vfscanf(stream, format, list); 448 360 va_end(list); 449 361 return result; … … 456 368 * @return The number of converted output items or EOF on failure. 457 369 */ 458 int posix_scanf(const char *restrict format, ...)370 int scanf(const char *restrict format, ...) 459 371 { 460 372 va_list list; 461 373 va_start(list, format); 462 int result = posix_vscanf(format, list);374 int result = vscanf(format, list); 463 375 va_end(list); 464 376 return result; … … 472 384 * @return The number of converted output items or EOF on failure. 473 385 */ 474 int posix_vscanf(const char *restrict format, va_list arg)475 { 476 return posix_vfscanf(stdin, format, arg);386 int vscanf(const char *restrict format, va_list arg) 387 { 388 return vfscanf(stdin, format, arg); 477 389 } 478 390 … … 484 396 * @return The number of converted output items or EOF on failure. 485 397 */ 486 int posix_sscanf(const char *restrict s, const char *restrict format, ...)398 int sscanf(const char *restrict s, const char *restrict format, ...) 487 399 { 488 400 va_list list; 489 401 va_start(list, format); 490 int result = posix_vsscanf(s, format, list);402 int result = vsscanf(s, format, list); 491 403 va_end(list); 492 404 return result; … … 498 410 * @param file File stream to lock. 499 411 */ 500 void posix_flockfile(FILE *file)412 void flockfile(FILE *file) 501 413 { 502 414 /* dummy */ … … 509 421 * @return Zero for success and non-zero if the lock cannot be acquired. 510 422 */ 511 int posix_ftrylockfile(FILE *file)423 int ftrylockfile(FILE *file) 512 424 { 513 425 /* dummy */ … … 520 432 * @param file File stream to unlock. 521 433 */ 522 void posix_funlockfile(FILE *file)434 void funlockfile(FILE *file) 523 435 { 524 436 /* dummy */ … … 531 443 * @return Either read byte or EOF. 532 444 */ 533 int posix_getc_unlocked(FILE *stream)445 int getc_unlocked(FILE *stream) 534 446 { 535 447 return getc(stream); … … 541 453 * @return Either read byte or EOF. 542 454 */ 543 int posix_getchar_unlocked(void)455 int getchar_unlocked(void) 544 456 { 545 457 return getchar(); … … 553 465 * @return Either written byte or EOF. 554 466 */ 555 int p osix_putc_unlocked(int c, FILE *stream)467 int putc_unlocked(int c, FILE *stream) 556 468 { 557 469 return putc(c, stream); … … 564 476 * @return Either written byte or EOF. 565 477 */ 566 int p osix_putchar_unlocked(int c)478 int putchar_unlocked(int c) 567 479 { 568 480 return putchar(c); 569 }570 571 /**572 * Remove a file or directory.573 *574 * @param path Pathname of the file that shall be removed.575 * @return Zero on success, -1 (with errno set) otherwise.576 */577 int posix_remove(const char *path)578 {579 if (failed(vfs_unlink_path(path)))580 return -1;581 else582 return 0;583 }584 585 /**586 * Rename a file or directory.587 *588 * @param old Old pathname.589 * @param new New pathname.590 * @return Zero on success, -1 (with errno set) otherwise.591 */592 int posix_rename(const char *old, const char *new)593 {594 if (failed(vfs_rename_path(old, new)))595 return -1;596 else597 return 0;598 481 } 599 482 … … 604 487 * @return The value of s on success, NULL on failure. 605 488 */ 606 char * posix_tmpnam(char *s)607 { 608 assert(L_tmpnam >= posix_strlen("/tmp/tnXXXXXX"));489 char *tmpnam(char *s) 490 { 491 assert(L_tmpnam >= strlen("/tmp/tnXXXXXX")); 609 492 610 493 static char buffer[L_tmpnam + 1]; … … 613 496 } 614 497 615 posix_strcpy(s, "/tmp/tnXXXXXX");616 posix_mktemp(s);498 strcpy(s, "/tmp/tnXXXXXX"); 499 mktemp(s); 617 500 618 501 if (*s == '\0') { … … 631 514 * @return Newly allocated unique path for temporary file. NULL on failure. 632 515 */ 633 char * posix_tempnam(const char *dir, const char *pfx)516 char *tempnam(const char *dir, const char *pfx) 634 517 { 635 518 /* Sequence number of the filename. */ 636 519 static int seq = 0; 637 520 638 size_t dir_len = posix_strlen(dir);521 size_t dir_len = strlen(dir); 639 522 if (dir[dir_len - 1] == '/') { 640 523 dir_len--; 641 524 } 642 525 643 size_t pfx_len = posix_strlen(pfx);526 size_t pfx_len = strlen(pfx); 644 527 if (pfx_len > 5) { 645 528 pfx_len = 5; … … 655 538 656 539 char *res_ptr = result; 657 posix_strncpy(res_ptr, dir, dir_len);540 strncpy(res_ptr, dir, dir_len); 658 541 res_ptr += dir_len; 659 posix_strncpy(res_ptr, pfx, pfx_len);542 strncpy(res_ptr, pfx, pfx_len); 660 543 res_ptr += pfx_len; 661 544 … … 666 549 errno = EOK; 667 550 /* Check if the file exists. */ 668 if ( posix_access(result, F_OK) == -1) {551 if (access(result, F_OK) == -1) { 669 552 if (errno == ENOENT) { 670 553 errno = orig_errno; … … 694 577 * @return Newly allocated unique path for temporary file. NULL on failure. 695 578 */ 696 FILE * posix_tmpfile(void)579 FILE *tmpfile(void) 697 580 { 698 581 char filename[] = "/tmp/tfXXXXXX"; 699 int fd = posix_mkstemp(filename);582 int fd = mkstemp(filename); 700 583 if (fd == -1) { 701 584 /* errno set by mkstemp(). */ … … 704 587 705 588 /* Unlink the created file, so that it's removed on close(). */ 706 posix_unlink(filename);589 unlink(filename); 707 590 return fdopen(fd, "w+"); 708 591 } -
uspace/lib/posix/src/stdio/scanf.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include <assert.h> 39 36 … … 119 116 /* Initialize internal structures. */ 120 117 self->consumed = 0; 121 ssize_t fetched = posix_getline(118 ssize_t fetched = getline( 122 119 &self->window, &self->window_size, self->source.stream); 123 120 if (fetched != -1) { … … 140 137 /* Initialize internal structures. */ 141 138 self->consumed = 0; 142 self->fetched = posix_strlen(self->source.string);139 self->fetched = strlen(self->source.string); 143 140 self->window = (char *) self->source.string; 144 141 self->window_size = self->fetched + 1; … … 158 155 /* Do we need to fetch a new line from the source? */ 159 156 if (*self->cursor == '\0') { 160 ssize_t fetched = posix_getline(&self->window,157 ssize_t fetched = getline(&self->window, 161 158 &self->window_size, self->source.stream); 162 159 if (fetched != -1) { … … 208 205 * containing newline, while at the same time newline is the character 209 206 * that breaks the matching process. */ 210 int rc = posix_fseek( 211 self->source.stream, -1, SEEK_CUR); 207 int rc = fseek(self->source.stream, -1, SEEK_CUR); 212 208 if (rc == -1) { 213 209 /* Seek failed. */ 214 210 return 0; 215 211 } 216 ssize_t fetched = posix_getline(&self->window,212 ssize_t fetched = getline(&self->window, 217 213 &self->window_size, self->source.stream); 218 214 if (fetched != -1) { … … 266 262 if (*self->cursor == '\0') { 267 263 /* Window was completely consumed, fetch new data. */ 268 ssize_t fetched = posix_getline(&self->window,264 ssize_t fetched = getline(&self->window, 269 265 &self->window_size, self->source.stream); 270 266 if (fetched != -1) { … … 298 294 /* Try to correct the difference between the stream position and what was 299 295 * actually consumed. If it is not possible, continue anyway. */ 300 posix_fseek(self->source.stream, self->consumed - self->fetched, SEEK_CUR);296 fseek(self->source.stream, self->consumed - self->fetched, SEEK_CUR); 301 297 302 298 /* Destruct internal structures. */ … … 638 634 * than allowed by width. */ 639 635 if (width != -1) { 640 cur_duplicated = posix_strndup(cur_borrowed, width);636 cur_duplicated = strndup(cur_borrowed, width); 641 637 cur_limited = cur_duplicated; 642 638 } else { … … 812 808 * than allowed by width. */ 813 809 if (width != -1) { 814 cur_duplicated = posix_strndup(cur_borrowed, width);810 cur_duplicated = strndup(cur_borrowed, width); 815 811 cur_limited = cur_duplicated; 816 812 } else { … … 826 822 switch (length_mod) { 827 823 case LMOD_NONE: 828 fres = posix_strtof(cur_limited, (char **) &cur_updated);824 fres = strtof(cur_limited, (char **) &cur_updated); 829 825 break; 830 826 case LMOD_l: 831 dres = posix_strtod(cur_limited, (char **) &cur_updated);827 dres = strtod(cur_limited, (char **) &cur_updated); 832 828 break; 833 829 case LMOD_L: 834 ldres = posix_strtold(cur_limited, (char **) &cur_updated);830 ldres = strtold(cur_limited, (char **) &cur_updated); 835 831 break; 836 832 default: … … 1194 1190 * @return The number of converted output items or EOF on failure. 1195 1191 */ 1196 int posix_vfscanf(1192 int vfscanf( 1197 1193 FILE *restrict stream, const char *restrict format, va_list arg) 1198 1194 { … … 1214 1210 * @return The number of converted output items or EOF on failure. 1215 1211 */ 1216 int posix_vsscanf(1212 int vsscanf( 1217 1213 const char *restrict s, const char *restrict format, va_list arg) 1218 1214 { -
uspace/lib/posix/src/stdlib.c
re0f47f5 r7f9df7b9 34 34 */ 35 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 39 36 #include "internal/common.h" 40 37 #include "posix/stdlib.h" … … 60 57 * @param compare 61 58 */ 62 int posix_atexit(void (*func)(void))59 int atexit(void (*func)(void)) 63 60 { 64 61 // TODO: low priority, just a compile-time dependency of binutils … … 73 70 * @return Absolute value of the parameter. 74 71 */ 75 int posix_abs(int i)72 int abs(int i) 76 73 { 77 74 return i < 0 ? -i : i; … … 84 81 * @return Absolute value of the parameter. 85 82 */ 86 long posix_labs(long i)83 long labs(long i) 87 84 { 88 85 return i < 0 ? -i : i; … … 95 92 * @return Absolute value of the parameter. 96 93 */ 97 long long posix_llabs(long long i)94 long long llabs(long long i) 98 95 { 99 96 return i < 0 ? -i : i; … … 107 104 * @return Quotient and remainder packed into structure. 108 105 */ 109 posix_div_t posix_div(int numer, int denom)110 { 111 return ( posix_div_t) { .quot = numer / denom, .rem = numer % denom };106 div_t div(int numer, int denom) 107 { 108 return (div_t) { .quot = numer / denom, .rem = numer % denom }; 112 109 } 113 110 … … 119 116 * @return Quotient and remainder packed into structure. 120 117 */ 121 posix_ldiv_t posix_ldiv(long numer, long denom)122 { 123 return ( posix_ldiv_t) { .quot = numer / denom, .rem = numer % denom };118 ldiv_t ldiv(long numer, long denom) 119 { 120 return (ldiv_t) { .quot = numer / denom, .rem = numer % denom }; 124 121 } 125 122 … … 131 128 * @return Quotient and remainder packed into structure. 132 129 */ 133 posix_lldiv_t posix_lldiv(long long numer, long long denom) 134 { 135 return (posix_lldiv_t) { .quot = numer / denom, .rem = numer % denom }; 136 } 137 138 /** 139 * Array sorting utilizing the quicksort algorithm. 140 * 141 * @param array Array of elements to sort. 142 * @param count Number of elements in the array. 143 * @param size Width of each element. 144 * @param compare Decides relative ordering of two elements. 145 */ 146 void posix_qsort(void *array, size_t count, size_t size, 147 int (*compare)(const void *, const void *)) 148 { 149 qsort(array, count, size, compare); 130 lldiv_t lldiv(long long numer, long long denom) 131 { 132 return (lldiv_t) { .quot = numer / denom, .rem = numer % denom }; 150 133 } 151 134 … … 160 143 * @return Pointer to a matching element, or NULL if none can be found. 161 144 */ 162 void * posix_bsearch(const void *key, const void *base,145 void *bsearch(const void *key, const void *base, 163 146 size_t nmemb, size_t size, int (*compar)(const void *, const void *)) 164 147 { … … 195 178 * @return Value of the variable or NULL if such variable does not exist. 196 179 */ 197 char * posix_getenv(const char *name)180 char *getenv(const char *name) 198 181 { 199 182 return NULL; … … 206 189 * @return 207 190 */ 208 int p osix_putenv(char *string)191 int putenv(char *string) 209 192 { 210 193 // TODO: low priority, just a compile-time dependency of binutils … … 221 204 * or not (zero). 222 205 */ 223 int posix_system(const char *string) {206 int system(const char *string) { 224 207 // TODO: does nothing at the moment 225 208 not_implemented(); … … 237 220 * 238 221 */ 239 char * posix_realpath(const char *restrict name, char *restrict resolved)222 char *realpath(const char *restrict name, char *restrict resolved) 240 223 { 241 224 #ifndef PATH_MAX … … 279 262 /** 280 263 * Converts a string representation of a floating-point number to 281 * its native representation. See posix_strtold().264 * its native representation. See strtold(). 282 265 * 283 266 * @param nptr String representation of a floating-point number. 284 267 * @return Double-precision number resulting from the string conversion. 285 268 */ 286 double posix_atof(const char *nptr)287 { 288 return posix_strtod(nptr, NULL);269 double atof(const char *nptr) 270 { 271 return strtod(nptr, NULL); 289 272 } 290 273 291 274 /** 292 275 * Converts a string representation of a floating-point number to 293 * its native representation. See posix_strtold().276 * its native representation. See strtold(). 294 277 * 295 278 * @param nptr String representation of a floating-point number. … … 298 281 * @return Single-precision number resulting from the string conversion. 299 282 */ 300 float posix_strtof(const char *restrict nptr, char **restrict endptr)301 { 302 return (float) posix_strtold(nptr, endptr);283 float strtof(const char *restrict nptr, char **restrict endptr) 284 { 285 return (float) strtold(nptr, endptr); 303 286 } 304 287 305 288 /** 306 289 * Converts a string representation of a floating-point number to 307 * its native representation. See posix_strtold().290 * its native representation. See strtold(). 308 291 * 309 292 * @param nptr String representation of a floating-point number. … … 312 295 * @return Double-precision number resulting from the string conversion. 313 296 */ 314 double posix_strtod(const char *restrict nptr, char **restrict endptr) 315 { 316 return (double) posix_strtold(nptr, endptr); 317 } 318 319 /** 320 * Allocate memory chunk. 321 * 322 * @param size Size of the chunk to allocate. 323 * @return Either pointer to the allocated chunk or NULL if not possible. 324 */ 325 void *posix_malloc(size_t size) 326 { 327 return malloc(size); 328 } 329 330 /** 331 * Allocate memory for an array of elements. 332 * 333 * @param nelem Number of elements in the array. 334 * @param elsize Size of each element. 335 * @return Either pointer to the allocated array or NULL if not possible. 336 */ 337 void *posix_calloc(size_t nelem, size_t elsize) 338 { 339 return calloc(nelem, elsize); 340 } 341 342 /** 343 * Reallocate memory chunk to a new size. 344 * 345 * @param ptr Memory chunk to reallocate. Might be NULL. 346 * @param size Size of the reallocated chunk. Might be zero. 347 * @return Either NULL or the pointer to the newly reallocated chunk. 348 */ 349 void *posix_realloc(void *ptr, size_t size) 350 { 351 if (ptr != NULL && size == 0) { 352 /* Native realloc does not handle this special case. */ 353 free(ptr); 354 return NULL; 355 } else { 356 return realloc(ptr, size); 357 } 358 } 359 360 /** 361 * Free allocated memory chunk. 362 * 363 * @param ptr Memory chunk to be freed. 364 */ 365 void posix_free(void *ptr) 366 { 367 if (ptr) { 368 free(ptr); 369 } 370 } 371 372 /** 373 * Generate a pseudo random integer in the range 0 to RAND_MAX inclusive. 374 * 375 * @return The pseudo random integer. 376 */ 377 int posix_rand(void) 378 { 379 return (int) rand(); 380 } 381 382 /** 383 * Initialize a new sequence of pseudo-random integers. 384 * 385 * @param seed The seed of the new sequence. 386 */ 387 void posix_srand(unsigned int seed) 388 { 389 srand(seed); 297 double strtod(const char *restrict nptr, char **restrict endptr) 298 { 299 return (double) strtold(nptr, endptr); 390 300 } 391 301 … … 396 306 * @return The opened file descriptor or -1 on error. 397 307 */ 398 int posix_mkstemp(char *tmpl)308 int mkstemp(char *tmpl) 399 309 { 400 310 int fd = -1; 401 311 402 char *tptr = tmpl + posix_strlen(tmpl) - 6;312 char *tptr = tmpl + strlen(tmpl) - 6; 403 313 404 314 while (fd < 0) { 405 if (* posix_mktemp(tmpl) == '\0') {315 if (*mktemp(tmpl) == '\0') { 406 316 /* Errno set by mktemp(). */ 407 317 return -1; 408 318 } 409 319 410 fd = posix_open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);320 fd = open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); 411 321 412 322 if (fd == -1) { … … 427 337 * reduced to an empty string. 428 338 */ 429 char * posix_mktemp(char *tmpl)430 { 431 int tmpl_len = posix_strlen(tmpl);339 char *mktemp(char *tmpl) 340 { 341 int tmpl_len = strlen(tmpl); 432 342 if (tmpl_len < 6) { 433 343 errno = EINVAL; … … 437 347 438 348 char *tptr = tmpl + tmpl_len - 6; 439 if ( posix_strcmp(tptr, "XXXXXX") != 0) {349 if (strcmp(tptr, "XXXXXX") != 0) { 440 350 errno = EINVAL; 441 351 *tmpl = '\0'; … … 451 361 errno = 0; 452 362 /* Check if the file exists. */ 453 if ( posix_access(tmpl, F_OK) == -1) {363 if (access(tmpl, F_OK) == -1) { 454 364 if (errno == ENOENT) { 455 365 errno = orig_errno; -
uspace/lib/posix/src/stdlib/strtold.c
re0f47f5 r7f9df7b9 32 32 /** @file Backend for floating point conversions. 33 33 */ 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 34 38 35 #include "../internal/common.h" … … 407 404 * @return An approximate representation of the input floating-point number. 408 405 */ 409 long double posix_strtold(const char *restrict nptr, char **restrict endptr)406 long double strtold(const char *restrict nptr, char **restrict endptr) 410 407 { 411 408 assert(nptr != NULL); … … 433 430 434 431 /* check for NaN */ 435 if ( posix_strncasecmp(&nptr[i], "nan", 3) == 0) {432 if (strncasecmp(&nptr[i], "nan", 3) == 0) { 436 433 // FIXME: return NaN 437 434 // TODO: handle the parenthesised case … … 445 442 446 443 /* check for Infinity */ 447 if ( posix_strncasecmp(&nptr[i], "inf", 3) == 0) {444 if (strncasecmp(&nptr[i], "inf", 3) == 0) { 448 445 i += 3; 449 if ( posix_strncasecmp(&nptr[i], "inity", 5) == 0) {446 if (strncasecmp(&nptr[i], "inity", 5) == 0) { 450 447 i += 5; 451 448 } -
uspace/lib/posix/src/string.c
re0f47f5 r7f9df7b9 34 34 */ 35 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 39 36 #include "internal/common.h" 40 37 #include "posix/string.h" … … 62 59 static char *strpbrk_null(const char *s1, const char *s2) 63 60 { 64 while (! posix_strchr(s2, *s1)) {61 while (!strchr(s2, *s1)) { 65 62 ++s1; 66 63 } … … 76 73 * @return Pointer to the destination buffer. 77 74 */ 78 char * posix_strcpy(char *restrict dest, const char *restrict src)79 { 80 posix_stpcpy(dest, src);75 char *strcpy(char *restrict dest, const char *restrict src) 76 { 77 stpcpy(dest, src); 81 78 return dest; 82 79 } … … 90 87 * @return Pointer to the destination buffer. 91 88 */ 92 char * posix_strncpy(char *restrict dest, const char *restrict src, size_t n)93 { 94 posix_stpncpy(dest, src, n);89 char *strncpy(char *restrict dest, const char *restrict src, size_t n) 90 { 91 stpncpy(dest, src, n); 95 92 return dest; 96 93 } … … 103 100 * @return Pointer to the nul character in the destination string. 104 101 */ 105 char * posix_stpcpy(char *restrict dest, const char *restrict src)102 char *stpcpy(char *restrict dest, const char *restrict src) 106 103 { 107 104 assert(dest != NULL); … … 129 126 * @return Pointer to the first written nul character or &dest[n]. 130 127 */ 131 char * posix_stpncpy(char *restrict dest, const char *restrict src, size_t n)128 char *stpncpy(char *restrict dest, const char *restrict src, size_t n) 132 129 { 133 130 assert(dest != NULL); … … 159 156 * @return Pointer to destination buffer. 160 157 */ 161 char * posix_strcat(char *restrict dest, const char *restrict src)158 char *strcat(char *restrict dest, const char *restrict src) 162 159 { 163 160 assert(dest != NULL); 164 161 assert(src != NULL); 165 162 166 posix_strcpy(posix_strchr(dest, '\0'), src);163 strcpy(strchr(dest, '\0'), src); 167 164 return dest; 168 165 } … … 176 173 * @return Pointer to destination buffer. 177 174 */ 178 char * posix_strncat(char *restrict dest, const char *restrict src, size_t n)175 char *strncat(char *restrict dest, const char *restrict src, size_t n) 179 176 { 180 177 assert(dest != NULL); 181 178 assert(src != NULL); 182 179 183 char *zeroptr = posix_strncpy(posix_strchr(dest, '\0'), src, n);180 char *zeroptr = strncpy(strchr(dest, '\0'), src, n); 184 181 /* strncpy doesn't append the nul terminator, so we do it here */ 185 182 zeroptr[n] = '\0'; … … 196 193 * @return Pointer to the first byte after c in dest if found, NULL otherwise. 197 194 */ 198 void * posix_memccpy(void *restrict dest, const void *restrict src, int c, size_t n)195 void *memccpy(void *restrict dest, const void *restrict src, int c, size_t n) 199 196 { 200 197 assert(dest != NULL); … … 222 219 * @return Newly allocated copy of the string. 223 220 */ 224 char * posix_strdup(const char *s)225 { 226 return posix_strndup(s, SIZE_MAX);221 char *strdup(const char *s) 222 { 223 return strndup(s, SIZE_MAX); 227 224 } 228 225 … … 234 231 * @return Newly allocated string copy of length at most n. 235 232 */ 236 char * posix_strndup(const char *s, size_t n)233 char *strndup(const char *s, size_t n) 237 234 { 238 235 assert(s != NULL); 239 236 240 size_t len = posix_strnlen(s, n);237 size_t len = strnlen(s, n); 241 238 char *dup = malloc(len + 1); 242 239 if (dup == NULL) { … … 248 245 249 246 return dup; 250 }251 252 /**253 * Compare bytes in memory.254 *255 * @param mem1 First area of memory to be compared.256 * @param mem2 Second area of memory to be compared.257 * @param n Maximum number of bytes to be compared.258 * @return Difference of the first pair of inequal bytes,259 * or 0 if areas have the same content.260 */261 int posix_memcmp(const void *mem1, const void *mem2, size_t n)262 {263 assert(mem1 != NULL);264 assert(mem2 != NULL);265 266 const unsigned char *s1 = mem1;267 const unsigned char *s2 = mem2;268 269 for (size_t i = 0; i < n; ++i) {270 if (s1[i] != s2[i]) {271 return s1[i] - s2[i];272 }273 }274 275 return 0;276 247 } 277 248 … … 284 255 * or 0 if strings have the same content. 285 256 */ 286 int posix_strcmp(const char *s1, const char *s2)257 int strcmp(const char *s1, const char *s2) 287 258 { 288 259 assert(s1 != NULL); 289 260 assert(s2 != NULL); 290 261 291 return posix_strncmp(s1, s2, STR_NO_LIMIT);262 return strncmp(s1, s2, STR_NO_LIMIT); 292 263 } 293 264 … … 301 272 * or 0 if strings have the same content. 302 273 */ 303 int posix_strncmp(const char *s1, const char *s2, size_t n)274 int strncmp(const char *s1, const char *s2, size_t n) 304 275 { 305 276 assert(s1 != NULL); … … 327 298 * NULL pointer otherwise. 328 299 */ 329 void * posix_memchr(const void *mem, int c, size_t n)300 void *memchr(const void *mem, int c, size_t n) 330 301 { 331 302 assert(mem != NULL); … … 349 320 * NULL pointer otherwise. 350 321 */ 351 char * posix_strchr(const char *s, int c)322 char *strchr(const char *s, int c) 352 323 { 353 324 assert(s != NULL); … … 365 336 * NULL pointer otherwise. 366 337 */ 367 char * posix_strrchr(const char *s, int c)338 char *strrchr(const char *s, int c) 368 339 { 369 340 assert(s != NULL); 370 341 371 const char *ptr = posix_strchr(s, '\0');342 const char *ptr = strchr(s, '\0'); 372 343 373 344 /* the same as in strchr, except it loops in reverse direction */ … … 410 381 * NULL pointer otherwise. 411 382 */ 412 char * posix_strpbrk(const char *s1, const char *s2)383 char *strpbrk(const char *s1, const char *s2) 413 384 { 414 385 assert(s1 != NULL); … … 426 397 * @return Length of the prefix. 427 398 */ 428 size_t posix_strcspn(const char *s1, const char *s2)399 size_t strcspn(const char *s1, const char *s2) 429 400 { 430 401 assert(s1 != NULL); … … 442 413 * @return Length of the prefix. 443 414 */ 444 size_t posix_strspn(const char *s1, const char *s2)415 size_t strspn(const char *s1, const char *s2) 445 416 { 446 417 assert(s1 != NULL); … … 449 420 const char *ptr; 450 421 for (ptr = s1; *ptr != '\0'; ++ptr) { 451 if (! posix_strchr(s2, *ptr)) {422 if (!strchr(s2, *ptr)) { 452 423 break; 453 424 } … … 464 435 * not found. 465 436 */ 466 char * posix_strstr(const char *haystack, const char *needle)437 char *strstr(const char *haystack, const char *needle) 467 438 { 468 439 assert(haystack != NULL); … … 475 446 476 447 /* Preprocess needle. */ 477 size_t nlen = posix_strlen(needle);448 size_t nlen = strlen(needle); 478 449 size_t prefix_table[nlen + 1]; 479 450 … … 521 492 * exists. 522 493 */ 523 char * posix_strtok(char *s, const char *delim)494 char *strtok(char *s, const char *delim) 524 495 { 525 496 static char *next; 526 497 527 return posix_strtok_r(s, delim, &next);498 return strtok_r(s, delim, &next); 528 499 } 529 500 … … 541 512 * exists. 542 513 */ 543 char * posix_strtok_r(char *s, const char *delim, char **next)514 char *strtok_r(char *s, const char *delim, char **next) 544 515 { 545 516 char *start, *end; … … 549 520 550 521 /* Skip over leading delimiters. */ 551 while (*s && ( posix_strchr(delim, *s) != NULL)) ++s;522 while (*s && (strchr(delim, *s) != NULL)) ++s; 552 523 start = s; 553 524 554 525 /* Skip over token characters. */ 555 while (*s && ( posix_strchr(delim, *s) == NULL)) ++s;526 while (*s && (strchr(delim, *s) == NULL)) ++s; 556 527 end = s; 557 528 *next = (*s ? s + 1 : s); … … 576 547 * or 0 if strings have the same content. 577 548 */ 578 int posix_strcoll(const char *s1, const char *s2)549 int strcoll(const char *s1, const char *s2) 579 550 { 580 551 assert(s1 != NULL); 581 552 assert(s2 != NULL); 582 553 583 return posix_strcmp(s1, s2);554 return strcmp(s1, s2); 584 555 } 585 556 … … 596 567 * @return Length of the transformed string. 597 568 */ 598 size_t posix_strxfrm(char *restrict s1, const char *restrict s2, size_t n)569 size_t strxfrm(char *restrict s1, const char *restrict s2, size_t n) 599 570 { 600 571 assert(s1 != NULL || n == 0); 601 572 assert(s2 != NULL); 602 573 603 size_t len = posix_strlen(s2);574 size_t len = strlen(s2); 604 575 605 576 if (n > len) { 606 posix_strcpy(s1, s2);577 strcpy(s1, s2); 607 578 } 608 579 … … 616 587 * @return Error message. 617 588 */ 618 char * posix_strerror(int errnum)589 char *strerror(int errnum) 619 590 { 620 591 // FIXME: move strerror() and strerror_r() to libc. … … 630 601 * @return Zero on success, errno otherwise. 631 602 */ 632 int posix_strerror_r(int errnum, char *buf, size_t bufsz)603 int strerror_r(int errnum, char *buf, size_t bufsz) 633 604 { 634 605 assert(buf != NULL); 635 606 636 char *errstr = posix_strerror(errnum);637 638 if ( posix_strlen(errstr) + 1 > bufsz) {607 char *errstr = strerror(errnum); 608 609 if (strlen(errstr) + 1 > bufsz) { 639 610 return ERANGE; 640 611 } else { 641 posix_strcpy(buf, errstr);612 strcpy(buf, errstr); 642 613 } 643 614 … … 651 622 * @return Length of the string. 652 623 */ 653 size_t posix_strlen(const char *s)624 size_t strlen(const char *s) 654 625 { 655 626 assert(s != NULL); 656 627 657 return (size_t) ( posix_strchr(s, '\0') - s);628 return (size_t) (strchr(s, '\0') - s); 658 629 } 659 630 … … 665 636 * @return The lower of either string length or n limit. 666 637 */ 667 size_t posix_strnlen(const char *s, size_t n)638 size_t strnlen(const char *s, size_t n) 668 639 { 669 640 assert(s != NULL); … … 685 656 * @return Human readable signal description. 686 657 */ 687 char * posix_strsignal(int signum)658 char *strsignal(int signum) 688 659 { 689 660 static const char *const sigstrings[] = { -
uspace/lib/posix/src/strings.c
re0f47f5 r7f9df7b9 34 34 */ 35 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 39 36 #include "internal/common.h" 40 37 #include "posix/strings.h" … … 52 49 * @return Index of first set bit. Bits are numbered starting at one. 53 50 */ 54 int posix_ffs(int i)51 int ffs(int i) 55 52 { 56 53 if (i == 0) { … … 92 89 * or 0 if strings have the same content. 93 90 */ 94 int posix_strcasecmp(const char *s1, const char *s2)91 int strcasecmp(const char *s1, const char *s2) 95 92 { 96 return posix_strncasecmp(s1, s2, STR_NO_LIMIT);93 return strncasecmp(s1, s2, STR_NO_LIMIT); 97 94 } 98 95 … … 106 103 * or 0 if strings have the same content. 107 104 */ 108 int posix_strncasecmp(const char *s1, const char *s2, size_t n)105 int strncasecmp(const char *s1, const char *s2, size_t n) 109 106 { 110 107 for (size_t i = 0; i < n; ++i) { … … 131 128 * zero. Otherwise return non-zero. 132 129 */ 133 int posix_bcmp(const void *mem1, const void *mem2, size_t n)130 int bcmp(const void *mem1, const void *mem2, size_t n) 134 131 { 135 132 return memcmp(mem1, mem2, n); … … 143 140 * @param n Number of bytes to copy. 144 141 */ 145 void posix_bcopy(const void *src, void *dest, size_t n)142 void bcopy(const void *src, void *dest, size_t n) 146 143 { 147 144 /* Note that memmove has different order of arguments. */ … … 155 152 * @param n Number of bytes to reset. 156 153 */ 157 void posix_bzero(void *mem, size_t n)154 void bzero(void *mem, size_t n) 158 155 { 159 156 memset(mem, 0, n); … … 168 165 * NULL pointer otherwise. 169 166 */ 170 char * posix_index(const char *s, int c)167 char *index(const char *s, int c) 171 168 { 172 return posix_strchr(s, c);169 return strchr(s, c); 173 170 } 174 171 … … 181 178 * NULL pointer otherwise. 182 179 */ 183 char * posix_rindex(const char *s, int c)180 char *rindex(const char *s, int c) 184 181 { 185 return posix_strrchr(s, c);182 return strrchr(s, c); 186 183 } 187 184 -
uspace/lib/posix/src/sys/mman.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "../internal/common.h" 39 36 #include <posix/sys/mman.h> … … 42 39 #include <posix/unistd.h> 43 40 44 void * posix_mmap(void *start, size_t length, int prot, int flags, int fd,45 __POSIX_DEF__(off_t)offset)41 void *mmap(void *start, size_t length, int prot, int flags, int fd, 42 off_t offset) 46 43 { 47 44 if (!start) … … 57 54 } 58 55 59 int posix_munmap(void *start, size_t length)56 int munmap(void *start, size_t length) 60 57 { 61 58 int rc = as_area_destroy(start); -
uspace/lib/posix/src/sys/stat.c
re0f47f5 r7f9df7b9 34 34 */ 35 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 39 36 #include "../internal/common.h" 40 37 #include "posix/sys/stat.h" … … 52 49 * @return 0 on success, -1 on error. 53 50 */ 54 static int stat_to_posix(struct posix_stat *dest, vfs_stat_t *src)51 static int stat_to_posix(struct stat *dest, vfs_stat_t *src) 55 52 { 56 memset(dest, 0, sizeof(struct posix_stat));53 memset(dest, 0, sizeof(struct stat)); 57 54 58 55 dest->st_dev = src->service; … … 86 83 * @return Zero on success, -1 otherwise. 87 84 */ 88 int posix_fstat(int fd, struct posix_stat *st)85 int fstat(int fd, struct stat *st) 89 86 { 90 87 vfs_stat_t hst; … … 101 98 * @return Zero on success, -1 otherwise. 102 99 */ 103 int posix_lstat(const char *restrict path, struct posix_stat *restrict st)100 int lstat(const char *restrict path, struct stat *restrict st) 104 101 { 105 102 /* There are currently no symbolic links in HelenOS. */ 106 return posix_stat(path, st);103 return stat(path, st); 107 104 } 108 105 … … 114 111 * @return Zero on success, -1 otherwise. 115 112 */ 116 int posix_stat(const char *restrict path, struct posix_stat *restrict st)113 int stat(const char *restrict path, struct stat *restrict st) 117 114 { 118 115 vfs_stat_t hst; … … 129 126 * @return Zero on success, -1 otherwise. 130 127 */ 131 int posix_chmod(const char *path, posix_mode_t mode)128 int chmod(const char *path, mode_t mode) 132 129 { 133 130 /* HelenOS doesn't support permissions, return success. */ … … 142 139 * @return Previous file mode creation mask. 143 140 */ 144 posix_mode_t posix_umask(posix_mode_t mask)141 mode_t umask(mode_t mask) 145 142 { 146 143 /* HelenOS doesn't support permissions, return empty mask. */ … … 155 152 * @return Zero on success, -1 otherwise. 156 153 */ 157 int posix_mkdir(const char *path, posix_mode_t mode)154 int mkdir(const char *path, mode_t mode) 158 155 { 159 156 if (failed(vfs_link_path(path, KIND_DIRECTORY, NULL))) -
uspace/lib/posix/src/sys/wait.c
re0f47f5 r7f9df7b9 33 33 /** @file Support for waiting. 34 34 */ 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 35 39 36 #include "../internal/common.h" … … 76 73 * -1 on signal interrupt, (pid_t)-1 otherwise. 77 74 */ 78 p osix_pid_t posix_wait(int *stat_ptr)75 pid_t wait(int *stat_ptr) 79 76 { 80 77 /* HelenOS does not support this. */ 81 78 errno = ENOSYS; 82 return (p osix_pid_t) -1;79 return (pid_t) -1; 83 80 } 84 81 … … 94 91 * no child process whose status can be reported, (pid_t)-1 otherwise. 95 92 */ 96 p osix_pid_t posix_waitpid(posix_pid_t pid, int *stat_ptr, int options)93 pid_t waitpid(pid_t pid, int *stat_ptr, int options) 97 94 { 98 95 assert(stat_ptr != NULL); … … 104 101 if (failed(task_wait_task_id((task_id_t) pid, &texit, &retval))) { 105 102 /* Unable to retrieve status. */ 106 return (p osix_pid_t) -1;103 return (pid_t) -1; 107 104 } 108 105 -
uspace/lib/posix/src/time.c
re0f47f5 r7f9df7b9 34 34 */ 35 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 39 36 #include "internal/common.h" 40 37 #include "posix/time.h" … … 70 67 * Set timezone conversion information. 71 68 */ 72 void posix_tzset(void)69 void tzset(void) 73 70 { 74 71 // TODO: read environment … … 80 77 81 78 /** 82 * Get the time in seconds83 *84 * @param t If t is non-NULL, the return value is also stored in the memory85 * pointed to by t.86 * @return On success, the value of time in seconds since the Epoch87 * is returned. On error, (time_t)-1 is returned.88 */89 time_t posix_time(time_t *t)90 {91 return time(t);92 }93 94 /**95 79 * Converts a time value to a broken-down UTC time. 96 80 * … … 99 83 * @return Value of result on success, NULL on overflow. 100 84 */ 101 struct tm * posix_gmtime_r(const time_t *restrict timer,85 struct tm *gmtime_r(const time_t *restrict timer, 102 86 struct tm *restrict result) 103 87 { … … 117 101 * the result, NULL in case of error. 118 102 */ 119 struct tm * posix_gmtime(const time_t *restrict timep)103 struct tm *gmtime(const time_t *restrict timep) 120 104 { 121 105 static struct tm result; 122 106 123 return posix_gmtime_r(timep, &result);107 return gmtime_r(timep, &result); 124 108 } 125 109 … … 131 115 * @return Value of result on success, NULL on overflow. 132 116 */ 133 struct tm * posix_localtime_r(const time_t *restrict timer,117 struct tm *localtime_r(const time_t *restrict timer, 134 118 struct tm *restrict result) 135 119 { 136 120 // TODO: deal with timezone 137 121 // currently assumes system and all times are in GMT 138 return posix_gmtime_r(timer, result);122 return gmtime_r(timer, result); 139 123 } 140 124 … … 147 131 * the result, NULL in case of error. 148 132 */ 149 struct tm * posix_localtime(const time_t *restrict timep)133 struct tm *localtime(const time_t *restrict timep) 150 134 { 151 135 static struct tm result; 152 136 153 return posix_localtime_r(timep, &result);137 return localtime_r(timep, &result); 154 138 } 155 139 … … 163 147 * @return Value of buf. 164 148 */ 165 char * posix_asctime_r(const struct tm *restrict timeptr,149 char *asctime_r(const struct tm *restrict timeptr, 166 150 char *restrict buf) 167 151 { … … 179 163 * the result, NULL in case of error. 180 164 */ 181 char * posix_asctime(const struct tm *restrict timeptr)165 char *asctime(const struct tm *restrict timeptr) 182 166 { 183 167 static char buf[ASCTIME_BUF_LEN]; 184 168 185 return posix_asctime_r(timeptr, buf);169 return asctime_r(timeptr, buf); 186 170 } 187 171 … … 195 179 * @return Pointer to buf on success, NULL on failure. 196 180 */ 197 char * posix_ctime_r(const time_t *timer, char *buf)181 char *ctime_r(const time_t *timer, char *buf) 198 182 { 199 183 if (failed(time_local2str(*timer, buf))) { … … 213 197 * the result, NULL in case of error. 214 198 */ 215 char * posix_ctime(const time_t *timep)199 char *ctime(const time_t *timep) 216 200 { 217 201 static char buf[ASCTIME_BUF_LEN]; 218 202 219 return posix_ctime_r(timep, buf);203 return ctime_r(timep, buf); 220 204 } 221 205 … … 227 211 * @return 0 on success, -1 with errno set on failure. 228 212 */ 229 int posix_clock_getres(posix_clockid_t clock_id, struct posix_timespec *res)213 int clock_getres(clockid_t clock_id, struct timespec *res) 230 214 { 231 215 assert(res != NULL); … … 249 233 * @return 0 on success, -1 with errno on failure. 250 234 */ 251 int posix_clock_gettime(posix_clockid_t clock_id, struct posix_timespec *tp)235 int clock_gettime(clockid_t clock_id, struct timespec *tp) 252 236 { 253 237 assert(tp != NULL); … … 275 259 * @return 0 on success, -1 with errno on failure. 276 260 */ 277 int posix_clock_settime(posix_clockid_t clock_id,278 const struct posix_timespec *tp)261 int clock_settime(clockid_t clock_id, 262 const struct timespec *tp) 279 263 { 280 264 assert(tp != NULL); … … 302 286 * @return 0 on success, -1 with errno set on failure. 303 287 */ 304 int posix_clock_nanosleep(posix_clockid_t clock_id, int flags,305 const struct posix_timespec *rqtp, struct posix_timespec *rmtp)288 int clock_nanosleep(clockid_t clock_id, int flags, 289 const struct timespec *rqtp, struct timespec *rmtp) 306 290 { 307 291 assert(rqtp != NULL); … … 329 313 * @return Consumed CPU cycles by this process or -1 if not available. 330 314 */ 331 posix_clock_t posix_clock(void)332 { 333 posix_clock_t total_cycles = -1;315 clock_t clock(void) 316 { 317 clock_t total_cycles = -1; 334 318 stats_task_t *task_stats = stats_get_task(task_get_id()); 335 319 if (task_stats) { 336 total_cycles = ( posix_clock_t) (task_stats->kcycles +320 total_cycles = (clock_t) (task_stats->kcycles + 337 321 task_stats->ucycles); 338 322 free(task_stats); -
uspace/lib/posix/src/unistd.c
re0f47f5 r7f9df7b9 34 34 */ 35 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 39 36 #include "internal/common.h" 40 37 #include "posix/unistd.h" … … 70 67 * @return Always 0 on HelenOS. 71 68 */ 72 unsigned int posix_sleep(unsigned int seconds)69 unsigned int sleep(unsigned int seconds) 73 70 { 74 71 return thread_sleep(seconds); … … 80 77 * @return User name (static) string or NULL if not found. 81 78 */ 82 char * posix_getlogin(void)79 char *getlogin(void) 83 80 { 84 81 /* There is currently no support for user accounts in HelenOS. */ … … 93 90 * @return Zero on success, error code otherwise. 94 91 */ 95 int posix_getlogin_r(char *name, size_t namesize)92 int getlogin_r(char *name, size_t namesize) 96 93 { 97 94 /* There is currently no support for user accounts in HelenOS. */ 98 95 if (namesize >= 5) { 99 posix_strcpy(name, (char *) "user");96 strcpy(name, (char *) "user"); 100 97 return 0; 101 98 } else { … … 111 108 * @return Boolean result of the test. 112 109 */ 113 int posix_isatty(int fd)110 int isatty(int fd) 114 111 { 115 112 // TODO … … 126 123 * @return Buffer pointer on success, NULL on failure. 127 124 */ 128 char * posix_getcwd(char *buf, size_t size)125 char *getcwd(char *buf, size_t size) 129 126 { 130 127 if (failed(vfs_cwd_get(buf, size))) … … 138 135 * @param path New working directory. 139 136 */ 140 int posix_chdir(const char *path)137 int chdir(const char *path) 141 138 { 142 139 if (failed(vfs_cwd_set(path))) … … 150 147 * @return Page size of the process. 151 148 */ 152 int posix_getpagesize(void)149 int getpagesize(void) 153 150 { 154 151 return PAGE_SIZE; … … 160 157 * @return Process ID. 161 158 */ 162 p osix_pid_t posix_getpid(void)159 pid_t getpid(void) 163 160 { 164 161 return task_get_id(); … … 170 167 * @return User ID. 171 168 */ 172 posix_uid_t posix_getuid(void)169 uid_t getuid(void) 173 170 { 174 171 /* There is currently no support for user accounts in HelenOS. */ … … 181 178 * @return Group ID. 182 179 */ 183 posix_gid_t posix_getgid(void)180 gid_t getgid(void) 184 181 { 185 182 /* There is currently no support for user accounts in HelenOS. */ … … 193 190 * @return 0 on success, -1 on error. 194 191 */ 195 int posix_close(int fildes)192 int close(int fildes) 196 193 { 197 194 posix_pos[fildes] = 0; … … 210 207 * @return Number of read bytes on success, -1 otherwise. 211 208 */ 212 ssize_t posix_read(int fildes, void *buf, size_t nbyte)209 ssize_t read(int fildes, void *buf, size_t nbyte) 213 210 { 214 211 size_t nread; … … 226 223 * @return Number of written bytes on success, -1 otherwise. 227 224 */ 228 ssize_t posix_write(int fildes, const void *buf, size_t nbyte)225 ssize_t write(int fildes, const void *buf, size_t nbyte) 229 226 { 230 227 size_t nwr; … … 243 240 * as measured in bytes from the beginning of the file, -1 otherwise. 244 241 */ 245 posix_off_t posix_lseek(int fildes, posix_off_t offset, int whence)242 off_t lseek(int fildes, off_t offset, int whence) 246 243 { 247 244 vfs_stat_t st; … … 274 271 * @return Zero on success, -1 otherwise. 275 272 */ 276 int posix_fsync(int fildes)273 int fsync(int fildes) 277 274 { 278 275 if (failed(vfs_sync(fildes))) … … 289 286 * @return Zero on success, -1 otherwise. 290 287 */ 291 int posix_ftruncate(int fildes, posix_off_t length)288 int ftruncate(int fildes, off_t length) 292 289 { 293 290 if (failed(vfs_resize(fildes, (aoff64_t) length))) … … 303 300 * @return Zero on success, -1 otherwise. 304 301 */ 305 int posix_rmdir(const char *path)302 int rmdir(const char *path) 306 303 { 307 304 if (failed(vfs_unlink_path(path))) … … 317 314 * @return Zero on success, -1 otherwise. 318 315 */ 319 int posix_unlink(const char *path)316 int unlink(const char *path) 320 317 { 321 318 if (failed(vfs_unlink_path(path))) … … 331 328 * @return On success, new file descriptor for the same file, otherwise -1. 332 329 */ 333 int posix_dup(int fildes)334 { 335 return posix_fcntl(fildes, F_DUPFD, 0);330 int dup(int fildes) 331 { 332 return fcntl(fildes, F_DUPFD, 0); 336 333 } 337 334 … … 344 341 * @return fildes2 on success, -1 otherwise. 345 342 */ 346 int posix_dup2(int fildes, int fildes2)343 int dup2(int fildes, int fildes2) 347 344 { 348 345 int file; … … 360 357 * @return Zero on success, -1 otherwise. 361 358 */ 362 int posix_access(const char *path, int amode)359 int access(const char *path, int amode) 363 360 { 364 361 if (amode == F_OK || (amode & (X_OK | W_OK | R_OK))) { … … 368 365 * Check file existence by attempting to open it. 369 366 */ 370 int fd = posix_open(path, O_RDONLY);367 int fd = open(path, O_RDONLY); 371 368 if (fd < 0) 372 369 return -1; 373 posix_close(fd);370 close(fd); 374 371 return 0; 375 372 } else { … … 386 383 * @return Variable value. 387 384 */ 388 long posix_sysconf(int name)385 long sysconf(int name) 389 386 { 390 387 long clk_tck = 0; … … 403 400 stats_physmem_t *mem_stats = stats_get_physmem(); 404 401 if (mem_stats) { 405 phys_pages = (long) (mem_stats->total / posix_getpagesize());406 avphys_pages = (long) (mem_stats->free / posix_getpagesize());402 phys_pages = (long) (mem_stats->total / getpagesize()); 403 avphys_pages = (long) (mem_stats->free / getpagesize()); 407 404 free(mem_stats); 408 405 mem_stats = 0; … … 415 412 return avphys_pages; 416 413 case _SC_PAGESIZE: 417 return posix_getpagesize();414 return getpagesize(); 418 415 case _SC_CLK_TCK: 419 416 return clk_tck; … … 430 427 * @return 431 428 */ 432 long p osix_pathconf(const char *path, int name)429 long pathconf(const char *path, int name) 433 430 { 434 431 // TODO: low priority, just a compile-time dependency of binutils … … 441 438 * @return 442 439 */ 443 p osix_pid_t posix_fork(void)440 pid_t fork(void) 444 441 { 445 442 // TODO: low priority, just a compile-time dependency of binutils … … 454 451 * @return 455 452 */ 456 int posix_execv(const char *path, char *const argv[])453 int execv(const char *path, char *const argv[]) 457 454 { 458 455 // TODO: low priority, just a compile-time dependency of binutils … … 467 464 * @return 468 465 */ 469 int posix_execvp(const char *file, char *const argv[])466 int execvp(const char *file, char *const argv[]) 470 467 { 471 468 // TODO: low priority, just a compile-time dependency of binutils … … 479 476 * @return 480 477 */ 481 int p osix_pipe(int fildes[2])478 int pipe(int fildes[2]) 482 479 { 483 480 // TODO: low priority, just a compile-time dependency of binutils … … 486 483 } 487 484 488 unsigned int posix_alarm(unsigned int seconds)485 unsigned int alarm(unsigned int seconds) 489 486 { 490 487 not_implemented(); -
uspace/lib/posix/test/scanf.c
re0f47f5 r7f9df7b9 27 27 */ 28 28 29 #define LIBPOSIX_INTERNAL 30 #define __POSIX_DEF__(x) posix_##x 29 31 30 32 31 #include <errno.h> … … 52 51 PCUT_TEST(int_decimal) { 53 52 int number; 54 int rc = posix_sscanf("4242", "%d", &number);53 int rc = sscanf("4242", "%d", &number); 55 54 PCUT_ASSERT_INT_EQUALS(1, rc); 56 55 PCUT_ASSERT_INT_EQUALS(4242, number); … … 59 58 PCUT_TEST(int_negative_decimal) { 60 59 int number; 61 int rc = posix_sscanf("-53", "%d", &number);60 int rc = sscanf("-53", "%d", &number); 62 61 PCUT_ASSERT_INT_EQUALS(1, rc); 63 62 PCUT_ASSERT_INT_EQUALS(-53, number); … … 83 82 void *p; 84 83 85 int rc = posix_sscanf(84 int rc = sscanf( 86 85 "\n j tt % \t -121314 98765 aqw 0765 0x77 0xABCDEF88 -99 884", 87 86 " j tt %%%3hhd%1hhu%3hd %3hu%u aqw%n %lo%llx %p %li %lld", … … 108 107 long double ld; 109 108 110 int rc = posix_sscanf(109 int rc = sscanf( 111 110 "\n \t\t1.0 -0x555.AP10 1234.5678e12", 112 111 "%f %lf %Lf", … … 124 123 char *pstr; 125 124 126 int rc = posix_sscanf(125 int rc = sscanf( 127 126 "\n\n\thello world \n", 128 127 "%5s %ms", … … 141 140 char *pscanset; 142 141 143 int rc = posix_sscanf(142 int rc = sscanf( 144 143 "\n\n\th-e-l-l-o world-] \n", 145 144 " %9[-eh-o] %m[^]-]", … … 158 157 char *pseq; 159 158 160 int rc = posix_sscanf(159 int rc = sscanf( 161 160 "\n\n\thello world \n", 162 161 " %5c %mc",
Note:
See TracChangeset
for help on using the changeset viewer.