Changes in / [10fdd0e:343d0da1] in mainline


Ignore:
Location:
uspace/lib/posix
Files:
5 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/Makefile

    r10fdd0e r343d0da1  
    4141        ctype.c \
    4242        fcntl.c \
    43         fnmatch.c \
    4443        math.c \
    45         pwd.c \
    4644        stdio.c \
    4745        stdlib.c \
    48         stdlib/strtol.c \
    4946        stdlib/strtold.c \
    5047        string.c \
  • uspace/lib/posix/signal.h

    r10fdd0e r343d0da1  
    3737
    3838#include "libc/errno.h"
    39 #include "sys/types.h"
    4039
    4140/* HelenOS doesn't have signals, so calls to functions of this header
     
    5251#undef SIG_ERR
    5352#define SIG_ERR ((void (*)(int)) 0)
    54 #undef SIG_HOLD
    55 #define SIG_HOLD ((void (*)(int)) 0)
    5653#undef SIG_IGN
    5754#define SIG_IGN ((void (*)(int)) 0)
     
    6259
    6360typedef int posix_sig_atomic_t;
    64 typedef int posix_sigset_t;
    65 typedef struct posix_mcontext {
    66         // FIXME: should not be empty to avoid compiler warnings (-pedantic)
    67         int dummy;
    68 } posix_mcontext_t;
    69 
    70 union posix_sigval {
    71         int sival_int;
    72         void *sival_ptr;
    73 };
    74 
    75 struct posix_sigevent {
    76         int sigev_notify; /* Notification type. */
    77         int sigev_signo; /* Signal number. */
    78         union posix_sigval sigev_value; /* Signal value. */
    79         void (*sigev_notify_function)(union posix_sigval); /* Notification function. */
    80         posix_thread_attr_t *sigev_notify_attributes; /* Notification attributes. */
    81 };
    82 
    83 typedef struct {
    84         int si_signo;
    85         int si_code;
    86 
    87         int si_errno;
    88 
    89         pid_t si_pid;
    90         uid_t si_uid;
    91         void *si_addr;
    92         int si_status;
    93 
    94         long si_band;
    95 
    96         union posix_sigval si_value;
    97 } posix_siginfo_t;
    98 
    99 struct posix_sigaction {
    100         void (*sa_handler)(int);
    101         posix_sigset_t sa_mask;
    102         int sa_flags;
    103         void (*sa_sigaction)(int, posix_siginfo_t *, void *);
    104 };
    105 
    106 typedef struct {
    107         void *ss_sp;
    108         size_t ss_size;
    109         int ss_flags;
    110 } posix_stack_t;
    111 
    112 typedef struct posix_ucontext {
    113         struct posix_ucontext *uc_link;
    114         posix_sigset_t uc_sigmask;
    115         posix_stack_t uc_stack;
    116         posix_mcontext_t uc_mcontext;
    117 } posix_ucontext_t;
    118 
    119 
    120 /* Values of posix_sigevent::sigev_notify */
    121 #undef SIGEV_NONE
    122 #define SIGEV_NONE 0
    123 #undef SIGEV_SIGNAL
    124 #define SIGEV_SIGNAL 0
    125 #undef SIGEV_THREAD
    126 #define SIGEV_THREAD 0
    127 
    128 #undef SIGRT_MIN
    129 #define SIGRT_MIN 0
    130 #undef SIGRT_MAX
    131 #define SIGRT_MAX 0
    132 
    133 #undef SIG_BLOCK
    134 #define SIG_BLOCK 0
    135 #undef SIG_UNBLOCK
    136 #define SIG_UNBLOCK 0
    137 #undef SIG_SETMASK
    138 #define SIG_SETMASK 0
    139 
    140 #undef SA_NOCLDSTOP
    141 #define SA_NOCLDSTOP 0
    142 #undef SA_ONSTACK
    143 #define SA_ONSTACK 0
    144 #undef SA_RESETHAND
    145 #define SA_RESETHAND 0
    146 #undef SA_RESTART
    147 #define SA_RESTART 0
    148 #undef SA_SIGINFO
    149 #define SA_SIGINFO 0
    150 #undef SA_NOCLDWAIT
    151 #define SA_NOCLDWAIT 0
    152 #undef SA_NODEFER
    153 #define SA_NODEFER 0
    154 
    155 #undef SS_ONSTACK
    156 #define SS_ONSTACK 0
    157 #undef SS_DISABLE
    158 #define SS_DISABLE 0
    159 
    160 #undef MINSIGSTKSZ
    161 #define MINSIGSTKSZ 0
    162 #undef SIGSTKSZ
    163 #define SIGSTKSZ 0
    16461
    16562/* full POSIX set */
     
    19592};
    19693
    197 /* Just declared to avoid compiler warnings. */
    198 extern int posix_sigemptyset(posix_sigset_t *set);
    199 extern int posix_sigprocmask(int how, const posix_sigset_t *restrict set,
    200     posix_sigset_t *restrict oset);
    201 
    20294#ifndef LIBPOSIX_INTERNAL
    20395        #define sig_atomic_t posix_sig_atomic_t
    204         #define sigset_t posix_sigset_t
    205         #define sigval posix_sigval
    206         #define sigevent posix_sigevent
    207         #define sigaction posix_sigaction
    208         #define mcontext_t posix_mcontext_t
    209         #define ucontext_t posix_ucontext_t
    210         #define stack_t posix_stack_t
    211         #define siginfo_t posix_siginfo_t
    212         #define sigemptyset posix_sigemptyset
    213         #define sigprocmask posix_sigprocmask
    21496#endif
    21597
  • uspace/lib/posix/stdio.h

    r10fdd0e r343d0da1  
    4242
    4343/* Character Input/Output */
    44 #undef putc
    4544#define putc fputc
    46 #undef getc
    4745#define getc fgetc
    4846extern int posix_ungetc(int c, FILE *stream);
     
    7068
    7169/* Temporary Files */
    72 #undef L_tmpnam
    73 #define L_tmpnam PATH_MAX
    74 
    7570extern char *posix_tmpnam(char *s);
    7671
  • uspace/lib/posix/stdlib.c

    r10fdd0e r343d0da1  
    3737
    3838#include "stdlib.h"
    39 #include "libc/sort.h"
    40 #include "libc/str.h"
    41 #include "libc/vfs/vfs.h"
    4239#include "internal/common.h"
    43 #include <errno.h>  // FIXME: use POSIX errno
    4440
    4541/**
     
    5854/**
    5955 *
    60  * @param i Input value.
    61  * @return Absolute value of the parameter.
    62  */
    63 int posix_abs(int i)
    64 {
    65         return i < 0 ? -i : i;
    66 }
    67 
    68 /**
    69  *
    70  * @param i Input value.
    71  * @return Absolute value of the parameter.
    72  */
    73 long posix_labs(long i)
    74 {
    75         return i < 0 ? -i : i;
    76 }
    77 
    78 /**
    79  *
    80  * @param i Input value.
    81  * @return Absolute value of the parameter.
    82  */
    83 long long posix_llabs(long long i)
    84 {
    85         return i < 0 ? -i : i;
    86 }
    87 
    88 posix_div_t posix_div(int numer, int denom)
    89 {
    90         return (posix_div_t) { .quot = numer / denom, .rem = numer % denom };
    91 }
    92 
    93 posix_ldiv_t posix_ldiv(long numer, long denom)
    94 {
    95         return (posix_ldiv_t) { .quot = numer / denom, .rem = numer % denom };
    96 }
    97 
    98 posix_lldiv_t posix_lldiv(long long numer, long long denom)
    99 {
    100         return (posix_lldiv_t) { .quot = numer / denom, .rem = numer % denom };
    101 }
    102 
    103 /**
    104  * Private helper function that serves as a compare function for qsort().
    105  *
    106  * @param elem1 First element to compare.
    107  * @param elem2 Second element to compare.
    108  * @param compare Comparison function without userdata parameter.
    109  *
    110  * @return Relative ordering of the elements.
    111  */
    112 static int sort_compare_wrapper(void *elem1, void *elem2, void *userdata)
    113 {
    114         int (*compare)(const void *, const void *) = userdata;
    115         return compare(elem1, elem2);
    116 }
    117 
    118 /**
    119  * Array sorting utilizing the quicksort algorithm.
    120  *
    12156 * @param array
    12257 * @param count
     
    12459 * @param compare
    12560 */
     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 */
    12674void posix_qsort(void *array, size_t count, size_t size,
    12775    int (*compare)(const void *, const void *))
    12876{
    129         /* Implemented in libc with one extra argument. */
    130         qsort(array, count, size, sort_compare_wrapper, compare);
    131 }
    132 
    133 /**
    134  * Binary search in a sorted array.
    135  *
    136  * @param key Object to search for.
    137  * @param base Pointer to the first element of the array.
    138  * @param nmemb Number of elements in the array.
    139  * @param size Size of each array element.
    140  * @param compar Comparison function.
    141  * @return Pointer to a matching element, or NULL if none can be found.
    142  */
    143 void *posix_bsearch(const void *key, const void *base,
    144     size_t nmemb, size_t size, int (*compar)(const void *, const void *))
    145 {
    146         while (nmemb > 0) {
    147                 const void *middle = base + (nmemb / 2) * size;
    148                 int cmp = compar(key, middle);
    149                 if (cmp == 0) {
    150                         return (void *) middle;
    151                 }
    152                 if (middle == base) {
    153                         /* There is just one member left to check and it
    154                          * didn't match the key. Avoid infinite loop.
    155                          */
    156                         break;
    157                 }
    158                 if (cmp < 0) {
    159                         nmemb = nmemb / 2;
    160                 } else if (cmp > 0) {
    161                         nmemb = nmemb - (nmemb / 2);
    162                         base = middle;
    163                 }
    164         }
    165        
    166         return NULL;
    167 }
    168 
    169 /**
    170  * Retrieve a value of the given environment variable.
    171  * Since HelenOS doesn't support env variables at the moment,
    172  * this function always returns NULL.
     77        // TODO
     78        not_implemented();
     79}
     80
     81/**
    17382 *
    17483 * @param name
    175  * @return Always NULL.
     84 * @return
    17685 */
    17786char *posix_getenv(const char *name)
    17887{
    179         return NULL;
     88        // TODO
     89        not_implemented();
    18090}
    18191
     
    193103
    194104/**
    195  *
    196  * @param string String to be passed to a command interpreter.
    197  * @return
    198  */
    199 int posix_system(const char *string) {
    200         // TODO: does nothing at the moment
    201         return 0;
    202 }
    203 
    204 /**
    205105 *
    206106 * @param name
     
    210110char *posix_realpath(const char *name, char *resolved)
    211111{
    212         #ifndef PATH_MAX
    213                 assert(resolved == NULL);
    214         #endif
    215        
    216         if (name == NULL) {
    217                 errno = EINVAL;
    218                 return NULL;
    219         }
    220        
    221         // TODO: symlink resolution
    222        
    223         /* Function absolutize is implemented in libc and declared in vfs.h.
    224          * No more processing is required as HelenOS doesn't have symlinks
    225          * so far (as far as I can tell), although this function will need
    226          * to be updated when that support is implemented.
    227          */
    228         char* absolute = absolutize(name, NULL);
    229        
    230         if (absolute == NULL) {
    231                 /* POSIX requires some specific errnos to be set
    232                  * for some cases, but there is no way to find out from
    233                  * absolutize().
    234                  */
    235                 errno = EINVAL;
    236                 return NULL;
    237         }
    238        
    239         if (resolved == NULL) {
    240                 return absolute;
    241         } else {
    242                 #ifdef PATH_MAX
    243                         str_cpy(resolved, PATH_MAX, absolute);
    244                 #endif
    245                 free(absolute);
    246                 return resolved;
    247         }
     112        // TODO
     113        not_implemented();
    248114}
    249115
     
    253119 *
    254120 * @param nptr
    255  * @return
    256  */
    257 double posix_atof(const char *nptr)
    258 {
    259         return posix_strtod(nptr, NULL);
     121 * @param endptr
     122 * @return
     123 */
     124float posix_strtof(const char *restrict nptr, char **restrict endptr)
     125{
     126        return (float) posix_strtold(nptr, endptr);
    260127}
    261128
     
    268135 * @return
    269136 */
    270 float posix_strtof(const char *restrict nptr, char **restrict endptr)
    271 {
    272         return (float) posix_strtold(nptr, endptr);
    273 }
    274 
    275 /**
    276  * Converts a string representation of a floating-point number to
    277  * its native representation. See posix_strtold().
    278  *
    279  * @param nptr
    280  * @param endptr
    281  * @return
    282  */
    283137double posix_strtod(const char *restrict nptr, char **restrict endptr)
    284138{
    285139        return (double) posix_strtold(nptr, endptr);
     140}
     141
     142/**
     143 *
     144 * @param str
     145 * @return
     146 */
     147int posix_atoi(const char *str)
     148{
     149        // TODO
     150        not_implemented();
    286151}
    287152
  • uspace/lib/posix/stdlib.h

    r10fdd0e r343d0da1  
    5353/* Absolute Value */
    5454extern int posix_abs(int i);
    55 extern long posix_labs(long i);
    56 extern long long posix_llabs(long long i);
    5755
    58 /* Integer division */
    59 
    60 typedef struct {
    61         int quot, rem;
    62 } posix_div_t;
    63 
    64 typedef struct {
    65         long quot, rem;
    66 } posix_ldiv_t;
    67 
    68 typedef struct {
    69         long long quot, rem;
    70 } posix_lldiv_t;
    71 
    72 extern posix_div_t posix_div(int numer, int denom);
    73 extern posix_ldiv_t posix_ldiv(long numer, long denom);
    74 extern posix_lldiv_t posix_lldiv(long long numer, long long denom);
    75 
    76 /* Array Functions */
     56/* Array Sort Function */
    7757extern void posix_qsort(void *array, size_t count, size_t size,
    7858    int (*compare)(const void *, const void *));
    79 extern void *posix_bsearch(const void *key, const void *base,
    80     size_t nmemb, size_t size, int (*compar)(const void *, const void *));
    81 
    8259
    8360/* Environment Access */
     
    8562extern int posix_putenv(char *string);
    8663
    87 extern int posix_system(const char *string);
    88 
    89 
    9064/* Symbolic Links */
    9165extern char *posix_realpath(const char *restrict name, char *restrict resolved);
    9266
    9367/* Floating Point Conversion */
    94 extern double posix_atof(const char *nptr);
    9568extern float posix_strtof(const char *restrict nptr, char **restrict endptr);
    9669extern double posix_strtod(const char *restrict nptr, char **restrict endptr);
     
    9871
    9972/* Integer Conversion */
    100 extern int posix_atoi(const char *nptr);
    101 extern long int posix_atol(const char *nptr);
    102 extern long long int posix_atoll(const char *nptr);
    103 
    104 extern long int posix_strtol(const char *restrict nptr,
    105     char **restrict endptr, int base);
    106 extern long long int posix_strtoll(const char *restrict nptr,
    107     char **restrict endptr, int base);
    108 extern unsigned long int posix_strtoul(const char *restrict nptr,
    109     char **restrict endptr, int base);
    110 extern unsigned long long int posix_strtoull(
    111     const char *restrict nptr, char **restrict endptr, int base);
    112 
     73extern int posix_atoi(const char *str);
    11374
    11475/* Memory Allocation */
     
    12586
    12687        #define abs posix_abs
    127         #define labs posix_labs
    128         #define llabs posix_llabs
    129 
    130         #define div_t posix_div_t
    131         #define ldiv_t posix_ldiv_t
    132         #define lldiv_t posix_lldiv_t
    133         #define div posix_div
    134         #define ldiv posix_ldiv
    135         #define lldiv posix_lldiv
    13688
    13789        #define qsort posix_qsort
    138         #define bsearch posix_bsearch
    13990
    14091        #define getenv posix_getenv
    141         #define putenv posix_putenv
    142         #define system posix_system
    14392
    14493        #define realpath posix_realpath
    14594       
    146         #define atof posix_atof
    14795        #define strtof posix_strtof
    14896        #define strtod posix_strtod
     
    15098       
    15199        #define atoi posix_atoi
    152         #define atol posix_atol
    153         #define atoll posix_atoll
    154         #define strtol posix_strtol
    155         #define strtoll posix_strtoll
    156         #define strtoul posix_strtoul
    157         #define strtoull posix_strtoull
    158100
    159101        #define malloc posix_malloc
  • uspace/lib/posix/sys/types.h

    r10fdd0e r343d0da1  
    4949typedef sysarg_t posix_dev_t;
    5050
    51 /* PThread types */
    52 typedef struct posix_thread_attr posix_thread_attr_t;
    53 
    5451#ifndef LIBPOSIX_INTERNAL
    5552        #define ino_t posix_ino_t
     
    6259        #define pid_t posix_pid_t
    6360        #define dev_t posix_dev_t
    64        
    65         #define pthread_attr_t posix_thread_attr_t
    6661#endif
    6762
Note: See TracChangeset for help on using the changeset viewer.