Changes in / [4d4988e:021c508] in mainline


Ignore:
Location:
uspace/lib/posix
Files:
4 added
18 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/Makefile

    r4d4988e r021c508  
    4141        ctype.c \
    4242        fcntl.c \
     43        math.c \
    4344        stdio.c \
    4445        stdlib.c \
     
    4748        strings.c \
    4849        sys/stat.c \
     50        sys/wait.c \
    4951        time.c \
    5052        unistd.c
  • uspace/lib/posix/ctype.c

    r4d4988e r021c508  
    3838#include "ctype.h"
    3939
     40// TODO: propose for inclusion in libc
     41
    4042/**
    41  *
    42  * @param ch
     43 * Checks whether character is a hexadecimal digit.
     44 *
     45 * @param c
    4346 * @return
    4447 */
    45 int posix_isxdigit(int ch)
     48int posix_isxdigit(int c)
    4649{
    47         return isdigit(ch) ||
    48             (ch >= 'a' && ch <= 'f') ||
    49             (ch >= 'A' && ch <= 'F');
     50        return isdigit(c) ||
     51            (c >= 'a' && c <= 'f') ||
     52            (c >= 'A' && c <= 'F');
     53}
     54
     55/**
     56 * Checks whether character is a word separator.
     57 *
     58 * @param c
     59 * @return
     60 */
     61int posix_isblank(int c)
     62{
     63        return c == ' ' || c == '\t';
     64}
     65
     66/**
     67 * Checks whether character is a control character.
     68 *
     69 * @param c
     70 * @return
     71 */
     72int posix_iscntrl(int c)
     73{
     74        return c < 0x20 || c == 0x7E;
     75}
     76
     77/**
     78 * Checks whether character is any printing character except space.
     79 *
     80 * @param c
     81 * @return
     82 */
     83int posix_isgraph(int c)
     84{
     85        return posix_isprint(c) && c != ' ';
     86}
     87
     88/**
     89 * Checks whether character is a printing character.
     90 *
     91 * @param c
     92 * @return
     93 */
     94int posix_isprint(int c)
     95{
     96        return !posix_iscntrl(c);
     97}
     98
     99/**
     100 * Checks whether character is a punctuation.
     101 *
     102 * @param c
     103 * @return
     104 */
     105int posix_ispunct(int c)
     106{
     107        return !isspace(c) && !isalnum(c);
    50108}
    51109
  • uspace/lib/posix/ctype.h

    r4d4988e r021c508  
    4040
    4141/* Classification of Characters */
    42 extern int posix_isxdigit(int ch);
     42extern int posix_isxdigit(int c);
     43extern int posix_isblank(int c);
     44extern int posix_iscntrl(int c);
     45extern int posix_isgraph(int c);
     46extern int posix_isprint(int c);
     47extern int posix_ispunct(int c);
    4348
    4449#ifndef LIBPOSIX_INTERNAL
    4550        #define isxdigit posix_isxdigit
     51        #define isblank posix_isblank
     52        #define iscntrl posix_iscntrl
     53        #define isgraph posix_isgraph
     54        #define isprint posix_isprint
     55        #define ispunct posix_ispunct
    4656#endif
    4757
  • uspace/lib/posix/limits.h

    r4d4988e r021c508  
    3636#define POSIX_LIMITS_H_
    3737
    38 #include "libc/stdint.h"
     38#include "stdint.h"
    3939#include "libc/sys/types.h"
    4040
  • uspace/lib/posix/math.h

    r4d4988e r021c508  
    3636#define POSIX_MATH_H_
    3737
    38 /* Empty. Just to satisfy preprocessor. */
     38/* Normalization Functions */
     39extern double posix_ldexp(double x, int exp);
     40extern double posix_frexp(double num, int *exp);
     41
     42#ifndef LIBPOSIX_INTERNAL
     43        #define ldexp posix_ldexp
     44        #define frexp posix_frexp
     45#endif
    3946
    4047#endif /* POSIX_MATH_H_ */
  • uspace/lib/posix/signal.h

    r4d4988e r021c508  
    5656#define signal(sig,func) (errno = ENOTSUP, SIG_ERR)
    5757#define raise(sig) ((int) -1)
     58#define kill(pid,sig) (errno = ENOTSUP, (int) -1)
    5859
    5960typedef int posix_sig_atomic_t;
  • uspace/lib/posix/stdint.h

    r4d4988e r021c508  
    3636#define POSIX_STDINT_H_
    3737
    38 #include "libc/stdint.h"
     38#undef INT8_MAX
     39#undef INT8_MIN
     40#define INT8_MAX  127
     41#define INT8_MIN  (-128)
     42
     43#undef UINT8_MAX
     44#undef UINT8_MIN
     45#define UINT8_MAX  255
     46#define UINT8_MIN  0
     47
     48#undef INT16_MAX
     49#undef INT16_MIN
     50#define INT16_MAX  32767
     51#define INT16_MIN  (-32768)
     52
     53#undef UINT16_MAX
     54#undef UINT16_MIN
     55#define UINT16_MAX  65535
     56#define UINT16_MIN  0
     57
     58#undef INT32_MAX
     59#undef INT32_MIN
     60#define INT32_MAX  2147483647
     61#define INT32_MIN  (-INT32_MAX - 1)
     62
     63#undef UINT32_MAX
     64#undef UINT32_MIN
     65#define UINT32_MAX  4294967295U
     66#define UINT32_MIN  0U
     67
     68#undef INT64_MAX
     69#undef INT64_MIN
     70#define INT64_MAX  9223372036854775807LL
     71#define INT64_MIN  (-INT64_MAX - 1LL)
     72
     73#undef UINT64_MAX
     74#undef  UINT64_MIN
     75#define UINT64_MAX  18446744073709551615ULL
     76#define UINT64_MIN  0ULL
     77
     78#undef OFF64_MAX
     79#undef OFF64_MIN
     80#define OFF64_MAX  INT64_MAX
     81#define OFF64_MIN  INT64_MIN
     82
     83#undef AOFF64_MAX
     84#undef AOFF64_MIN
     85#define AOFF64_MAX  UINT64_MAX
     86#define AOFF64_MIN  UINT64_MIN
     87
     88#include "libc/sys/types.h"
    3989
    4090typedef int64_t posix_intmax_t;
  • uspace/lib/posix/stdio.c

    r4d4988e r021c508  
    167167 * @return
    168168 */
     169int posix_vsprintf(char *s, const char *format, va_list ap)
     170{
     171        // TODO: low priority, just a compile-time dependency of binutils
     172        not_implemented();
     173}
     174
     175/**
     176 *
     177 * @param s
     178 * @param format
     179 * @param ...
     180 * @return
     181 */
    169182int posix_sscanf(const char *s, const char *format, ...)
    170183{
     
    173186}
    174187
     188/**
     189 *
     190 * @param path
     191 * @return
     192 */
     193int posix_remove(const char *path)
     194{
     195        // TODO: low priority, just a compile-time dependency of binutils
     196        not_implemented();
     197}
     198
     199/**
     200 *
     201 * @param s
     202 * @return
     203 */
     204char *posix_tmpnam(char *s)
     205{
     206        // TODO: low priority, just a compile-time dependency of binutils
     207        not_implemented();
     208}
     209
    175210/** @}
    176211 */
  • uspace/lib/posix/stdio.h

    r4d4988e r021c508  
    3939#include "libc/stdio.h"
    4040#include "sys/types.h"
     41#include "libc/stdarg.h"
    4142
    4243/* Character Input/Output */
     
    6061/* Formatted Input/Output */
    6162extern int posix_sprintf(char *restrict s, const char *restrict format, ...);
     63extern int posix_vsprintf(char *restrict s, const char *restrict format, va_list ap);
    6264extern int posix_sscanf(const char *restrict s, const char *restrict format, ...);
     65
     66/* Deleting Files */
     67extern int posix_remove(const char *path);
     68
     69/* Temporary Files */
     70extern char *posix_tmpnam(char *s);
    6371
    6472#ifndef LIBPOSIX_INTERNAL
     
    7381
    7482        #define sprintf posix_sprintf
     83        #define vsprintf posix_vsprintf
    7584        #define sscanf posix_sscanf
     85
     86        #define remove posix_remove
     87
     88        #define tmpnam posix_tmpnam
    7689#endif
    7790
  • uspace/lib/posix/stdlib.c

    r4d4988e r021c508  
    4040
    4141/**
    42  *
     42 * 
    4343 * @param array
    4444 * @param count
     
    4646 * @param compare
    4747 */
     48int posix_atexit(void (*func)(void))
     49{
     50        // TODO: low priority, just a compile-time dependency of binutils
     51        not_implemented();
     52}
     53
     54/**
     55 *
     56 * @param array
     57 * @param count
     58 * @param size
     59 * @param compare
     60 */
     61int posix_abs(int i)
     62{
     63        // TODO
     64        not_implemented();
     65}
     66
     67/**
     68 *
     69 * @param array
     70 * @param count
     71 * @param size
     72 * @param compare
     73 */
    4874void posix_qsort(void *array, size_t count, size_t size,
    4975    int (*compare)(const void *, const void *))
     
    7096 * @return
    7197 */
     98int posix_putenv(char *string)
     99{
     100        // TODO: low priority, just a compile-time dependency of binutils
     101        not_implemented();
     102}
     103
     104/**
     105 *
     106 * @param name
     107 * @param resolved
     108 * @return
     109 */
    72110char *posix_realpath(const char *name, char *resolved)
    73111{
     
    113151}
    114152
     153/**
     154 *
     155 * @param size
     156 * @return
     157 */
     158void *posix_malloc(size_t size)
     159{
     160        return malloc(size);
     161}
     162
     163/**
     164 *
     165 * @param nelem
     166 * @param elsize
     167 * @return
     168 */
     169void *posix_calloc(size_t nelem, size_t elsize)
     170{
     171        return calloc(nelem, elsize);
     172}
     173
     174/**
     175 *
     176 * @param ptr
     177 * @param size
     178 * @return
     179 */
     180void *posix_realloc(void *ptr, size_t size)
     181{
     182        return realloc(ptr, size);
     183}
     184
     185/**
     186 *
     187 * @param ptr
     188 */
     189void posix_free(void *ptr)
     190{
     191        free(ptr);
     192}
     193
     194/**
     195 *
     196 * @param tmpl
     197 * @return
     198 */
     199char *posix_mktemp(char *tmpl)
     200{
     201        // TODO: low priority, just a compile-time dependency of binutils
     202        not_implemented();
     203}
     204
    115205/** @}
    116206 */
  • uspace/lib/posix/stdlib.h

    r4d4988e r021c508  
    4949#define EXIT_SUCCESS 0
    5050#define _Exit exit
     51extern int posix_atexit(void (*func)(void));
     52
     53/* Absolute Value */
     54extern int posix_abs(int i);
    5155
    5256/* Array Sort Function */
     
    5660/* Environment Access */
    5761extern char *posix_getenv(const char *name);
     62extern int posix_putenv(char *string);
    5863
    5964/* Symbolic Links */
     
    6873extern int posix_atoi(const char *str);
    6974
     75/* Memory Allocation */
     76extern void *posix_malloc(size_t size);
     77extern void *posix_calloc(size_t nelem, size_t elsize);
     78extern void *posix_realloc(void *ptr, size_t size);
     79extern void posix_free(void *ptr);
     80
     81/* Legacy Declarations */
     82extern char *posix_mktemp(char *tmpl);
     83
    7084#ifndef LIBPOSIX_INTERNAL
     85        #define atexit posix_atexit
     86
     87        #define abs posix_abs
     88
    7189        #define qsort posix_qsort
     90
    7291        #define getenv posix_getenv
     92
    7393        #define realpath posix_realpath
    7494       
     
    7898       
    7999        #define atoi posix_atoi
     100
     101        #define malloc posix_malloc
     102        #define calloc posix_calloc
     103        #define realloc posix_realloc
     104        #define free posix_free
     105
     106        #define mktemp posix_mktemp
    80107#endif
    81108
  • uspace/lib/posix/stdlib/strtold.c

    r4d4988e r021c508  
    4141#include <errno.h> // TODO: use POSIX errno
    4242#include "../libc/bool.h"
    43 #include "../libc/stdint.h"
     43#include "../stdint.h"
    4444#include "../stdlib.h"
    4545#include "../strings.h"
  • uspace/lib/posix/string.h

    r4d4988e r021c508  
    103103
    104104/* Legacy declarations */
     105#ifndef POSIX_STRINGS_H_
    105106extern int posix_ffs(int i);
     107#endif
    106108
    107109#ifndef LIBPOSIX_INTERNAL
  • uspace/lib/posix/strings.h

    r4d4988e r021c508  
    3737#define POSIX_STRINGS_H_
    3838
     39#ifndef POSIX_STRING_H_
    3940/* Search Functions */
    4041extern int posix_ffs(int i);
     42#endif
    4143
    4244/* String/Array Comparison */
  • uspace/lib/posix/time.c

    r4d4988e r021c508  
    8787}
    8888
     89/**
     90 *
     91 * @return
     92 */
     93posix_clock_t posix_clock(void)
     94{
     95        // TODO
     96        not_implemented();
     97}
     98
    8999/** @}
    90100 */
  • uspace/lib/posix/time.h

    r4d4988e r021c508  
    5555};
    5656
     57typedef long posix_clock_t;
     58
    5759/* Broken-down Time */
    5860extern struct posix_tm *posix_localtime(const time_t *timep);
     
    6365extern size_t posix_strftime(char *restrict s, size_t maxsize, const char *restrict format, const struct posix_tm *restrict tm);
    6466
     67/* CPU Time */
     68extern posix_clock_t posix_clock(void);
     69
    6570#ifndef LIBPOSIX_INTERNAL
    6671        #define tm posix_tm
     72
     73        #define clock_t posix_clock_t
    6774
    6875        #define localtime posix_localtime
     
    7178        #define ctime posix_ctime
    7279        #define strftime posix_strftime
     80
     81        #define clock posix_clock
    7382#endif
    7483
  • uspace/lib/posix/unistd.c

    r4d4988e r021c508  
    3838#include "internal/common.h"
    3939#include "unistd.h"
     40#include <task.h>
    4041
    4142/* Array of environment variable strings (NAME=VALUE). */
     
    4344
    4445/**
    45  *
     46 * Dummy function. Always returns false, because there is no easy way to find
     47 * out under HelenOS.
     48 *
    4649 * @param fd
    47  * @return
     50 * @return Always false.
    4851 */
    4952int posix_isatty(int fd)
    5053{
    51         // TODO
    52         not_implemented();
     54        return false;
    5355}
    5456
     
    6062{
    6163        return getpagesize();
     64}
     65
     66/**
     67 *
     68 * @return
     69 */
     70posix_pid_t posix_getpid(void)
     71{
     72        return task_get_id();
    6273}
    6374
     
    105116}
    106117
     118/**
     119 *
     120 * @param path
     121 * @param name
     122 * @return
     123 */
     124long posix_pathconf(const char *path, int name)
     125{
     126        // TODO: low priority, just a compile-time dependency of binutils
     127        not_implemented();
     128}
     129
     130/**
     131 *
     132 * @return
     133 */
     134posix_pid_t posix_fork(void)
     135{
     136        // TODO: low priority, just a compile-time dependency of binutils
     137        not_implemented();
     138}
     139
     140/**
     141 *
     142 * @param path
     143 * @param argv
     144 * @return
     145 */
     146int posix_execv(const char *path, char *const argv[])
     147{
     148        // TODO: low priority, just a compile-time dependency of binutils
     149        not_implemented();
     150}
     151
     152/**
     153 *
     154 * @param file
     155 * @param argv
     156 * @return
     157 */
     158int posix_execvp(const char *file, char *const argv[])
     159{
     160        // TODO: low priority, just a compile-time dependency of binutils
     161        not_implemented();
     162}
     163
     164/**
     165 *
     166 * @param fildes
     167 * @return
     168 */
     169int posix_pipe(int fildes[2])
     170{
     171        // TODO: low priority, just a compile-time dependency of binutils
     172        not_implemented();
     173}
     174
    107175/** @}
    108176 */
  • uspace/lib/posix/unistd.h

    r4d4988e r021c508  
    5858
    5959/* Process Identification */
    60 #define getpid task_get_id
     60extern posix_pid_t posix_getpid(void);
    6161extern posix_uid_t posix_getuid(void);
    6262extern posix_gid_t posix_getgid(void);
     
    112112        _PC_VDISABLE
    113113};
     114extern long posix_pathconf(const char *path, int name);
     115
     116/* Creating a Process */
     117extern posix_pid_t posix_fork(void);
     118
     119/* Executing a File */
     120extern int posix_execv(const char *path, char *const argv[]);
     121extern int posix_execvp(const char *file, char *const argv[]);
     122
     123/* Creating a Pipe */
     124extern int posix_pipe(int fildes[2]);
    114125
    115126#ifndef LIBPOSIX_INTERNAL
     
    121132        #define getpagesize posix_getpagesize
    122133
     134        #define getpid posix_getpid
    123135        #define getuid posix_getuid
    124136        #define getgid posix_getgid
     
    127139
    128140        #define sysconf posix_sysconf
     141
     142        #define pathconf posix_pathconf
     143
     144        #define fork posix_fork
     145
     146        #define execv posix_execv
     147        #define execvp posix_execvp
     148
     149        #define pipe posix_pipe
    129150#endif
    130151
Note: See TracChangeset for help on using the changeset viewer.