Changes in / [0ffbed9:f48b637] in mainline


Ignore:
Location:
uspace/lib/posix
Files:
1 added
13 deleted
18 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/Makefile

    r0ffbed9 rf48b637  
    4040SOURCES = \
    4141        ctype.c \
    42         getopt.c \
    4342        stdio.c \
    4443        stdlib.c \
    45         stdlib/strtold.c \
    4644        string.c \
    4745        strings.c \
  • uspace/lib/posix/ctype.c

    r0ffbed9 rf48b637  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
    3  * Copyright (c) 2011 Petr Koupy
    43 * All rights reserved.
    54 *
     
    2827 */
    2928
    30 /** @addtogroup libposix
    31  * @{
    32  */
    33 /** @file
    34  */
    35 
    36 #define LIBPOSIX_INTERNAL
    37 
    3829#include "ctype.h"
    3930
    40 /**
    41  *
    42  * @param ch
    43  * @return
    44  */
    45 int posix_isxdigit(int ch)
     31int isxdigit(int ch)
    4632{
    4733        return isdigit(ch) ||
    48             (ch >= 'a' && ch <= 'f') ||
    49             (ch >= 'A' && ch <= 'F');
     34               (ch >= 'a' && ch <= 'f') ||
     35               (ch >= 'A' && ch <= 'F');
    5036}
    5137
    52 /** @}
    53  */
  • uspace/lib/posix/ctype.h

    r0ffbed9 rf48b637  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
    3  * Copyright (c) 2011 Petr Koupy
    43 * All rights reserved.
    54 *
     
    2827 */
    2928
    30 /** @addtogroup libposix
    31  * @{
    32  */
    33 /** @file
    34  */
    35 
    3629#ifndef POSIX_CTYPE_H_
    3730#define POSIX_CTYPE_H_
     
    3932#include "libc/ctype.h"
    4033
    41 /* Classification of Characters */
    42 extern int posix_isxdigit(int ch);
    43 
    44 #ifndef LIBPOSIX_INTERNAL
    45         #define isxdigit posix_isxdigit
    46 #endif
     34extern int isxdigit(int ch);
    4735
    4836#endif /* POSIX_CTYPE_H_ */
    4937
    50 /** @}
    51  */
  • uspace/lib/posix/signal.h

    r0ffbed9 rf48b637  
    2727 */
    2828
    29 /** @addtogroup libposix
    30  * @{
    31  */
    32 /** @file
    33  */
    34 
    3529#ifndef POSIX_SIGNAL_H_
    3630#define POSIX_SIGNAL_H_
    3731
    38 #include "libc/errno.h"
     32#include <errno.h>
    3933
    4034/* HelenOS doesn't have signals, so calls to functions of this header
     
    4741 */
    4842
    49 #undef SIG_DFL
    5043#define SIG_DFL ((void (*)(int)) 0)
    51 #undef SIG_ERR
    5244#define SIG_ERR ((void (*)(int)) 0)
    53 #undef SIG_IGN
    5445#define SIG_IGN ((void (*)(int)) 0)
    5546
    5647#define signal(sig,func) (errno = ENOTSUP, SIG_ERR)
    57 #define raise(sig) ((int) -1)
     48#define raise(sig) ((int)-1)
    5849
    59 typedef int posix_sig_atomic_t;
     50typedef int sig_atomic_t;
    6051
    6152/* full POSIX set */
     
    9182};
    9283
    93 #ifndef LIBPOSIX_INTERNAL
    94         #define sig_atomic_t posix_sig_atomic_t
    95 #endif
    96 
    9784#endif /* POSIX_SIGNAL_H_ */
    9885
    99 /** @}
    100  */
  • uspace/lib/posix/stdio.c

    r0ffbed9 rf48b637  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
    3  * Copyright (c) 2011 Petr Koupy
    43 * All rights reserved.
    54 *
     
    3433 */
    3534
    36 #define LIBPOSIX_INTERNAL
     35#define POSIX_INTERNAL
    3736
    3837#include <assert.h>
    39 #include <errno.h>
    40 
    41 #include "internal/common.h"
     38#include "errno.h"
     39#include "common.h"
    4240#include "stdio.h"
    4341#include "string.h"
    44 
    4542/* not the best of solutions, but freopen will eventually
    46  * need to be implemented in libc anyway
    47  */
     43   need to be implemented in libc anyway */
    4844#include "../c/generic/private/stdio.h"
    4945
    50 /**
    51  *
    52  * @param c
    53  * @param stream
    54  * @return
    55  */
    56 int posix_ungetc(int c, FILE *stream)
    57 {
    58         // TODO
    59         not_implemented();
    60 }
    61 
    62 /**
    63  *
    64  * @param filename
    65  * @param mode
    66  * @param stream
    67  * @return
    68  */
    69 FILE *posix_freopen(
    70     const char *restrict filename,
    71     const char *restrict mode,
    72     FILE *restrict stream)
     46FILE *posix_freopen(const char *restrict filename,
     47                    const char *restrict mode,
     48                    FILE *restrict stream)
    7349{
    7450        assert(mode != NULL);
     
    7955               
    8056                /* print error to stderr as well, to avoid hard to find problems
    81                  * with buggy apps that expect this to work
    82                  */
    83                 fprintf(stderr,
    84                     "ERROR: Application wants to use freopen() to change mode of opened stream.\n"
    85                     "       libposix does not support that yet, the application may function improperly.\n");
     57                   with buggy apps that expect this to work */
     58                fprintf(stderr, "ERROR: Application wants to use freopen() to change mode of opened stream.\n"
     59                                "       libposix does not support that yet, the application may function improperly.\n");
    8660                errno = ENOTSUP;
    8761                return NULL;
     
    9468        }
    9569        memcpy(copy, stream, sizeof(FILE));
    96         fclose(copy); /* copy is now freed */
     70        fclose(copy);   /* copy is now freed */
    9771       
    98         copy = fopen(filename, mode); /* open new stream */
     72        copy = fopen(filename, mode);         /* open new stream */
    9973        if (copy == NULL) {
    10074                /* fopen() sets errno */
     
    11387}
    11488
    115 /**
    116  *
    117  * @param s
    118  */
    11989void posix_perror(const char *s)
    120 {
    121         // TODO
    122         not_implemented();
    123 }
    124 
    125 /**
    126  *
    127  * @param stream
    128  * @param offset
    129  * @param whence
    130  * @return
    131  */
    132 int posix_fseeko(FILE *stream, posix_off_t offset, int whence)
    133 {
    134         // TODO
    135         not_implemented();
    136 }
    137 
    138 /**
    139  *
    140  * @param stream
    141  * @return
    142  */
    143 posix_off_t posix_ftello(FILE *stream)
    144 {
    145         // TODO
    146         not_implemented();
    147 }
    148 
    149 /**
    150  *
    151  * @param s
    152  * @param format
    153  * @param ...
    154  * @return
    155  */
    156 int posix_sprintf(char *s, const char *format, ...)
    157 {
    158         // TODO
    159         not_implemented();
    160 }
    161 
    162 /**
    163  *
    164  * @param s
    165  * @param format
    166  * @param ...
    167  * @return
    168  */
    169 int posix_sscanf(const char *s, const char *format, ...)
    17090{
    17191        // TODO
     
    17595/** @}
    17696 */
     97
  • uspace/lib/posix/stdio.h

    r0ffbed9 rf48b637  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
    3  * Copyright (c) 2011 Petr Koupy
    43 * All rights reserved.
    54 *
     
    2827 */
    2928
    30 /** @addtogroup libposix
    31  * @{
    32  */
    33 /** @file
    34  */
    35 
    3629#ifndef POSIX_STDIO_H_
    3730#define POSIX_STDIO_H_
    3831
    3932#include "libc/stdio.h"
    40 #include "sys/types.h"
    4133
    42 /* Character Input/Output */
    4334#define putc fputc
    4435#define getc fgetc
    45 extern int posix_ungetc(int c, FILE *stream);
    4636
    47 /* Opening Streams */
    48 extern FILE *posix_freopen(
    49    const char *restrict filename,
    50    const char *restrict mode,
    51    FILE *restrict stream);
    5237
    53 /* Error Messages */
     38extern FILE *posix_freopen(const char *restrict filename,
     39                           const char *restrict mode,
     40                           FILE *restrict stream);
     41
    5442extern void posix_perror(const char *s);
    5543
    56 /* File Positioning */
    57 extern int posix_fseeko(FILE *stream, posix_off_t offset, int whence);
    58 extern posix_off_t posix_ftello(FILE *stream);
    59 
    60 /* Formatted Input/Output */
    61 extern int posix_sprintf(char *restrict s, const char *restrict format, ...);
    62 extern int posix_sscanf(const char *restrict s, const char *restrict format, ...);
    63 
    64 #ifndef LIBPOSIX_INTERNAL
    65         #define ungetc posix_ungetc
    66 
     44#ifndef POSIX_INTERNAL
    6745        #define freopen posix_freopen
    68 
    6946        #define perror posix_perror
    70 
    71         #define fseeko posix_fseeko
    72         #define ftello posix_ftello
    73 
    74         #define sprintf posix_sprintf
    75         #define sscanf posix_sscanf
    7647#endif
    7748
    7849#endif /* POSIX_STDIO_H_ */
    7950
    80 /** @}
    81  */
  • uspace/lib/posix/stdlib.c

    r0ffbed9 rf48b637  
    3737
    3838#include "stdlib.h"
    39 #include "internal/common.h"
     39#include "common.h"
    4040
    4141/**
     
    4646 * @param compare
    4747 */
    48 void posix_qsort(void *array, size_t count, size_t size,
    49     int (*compare)(const void *, const void *))
     48void posix_qsort(void *array, size_t count, size_t size, int (*compare)(const void *, const void *))
    5049{
    5150        // TODO
     
    7776
    7877/**
    79  * Converts a string representation of a floating-point number to
    80  * its native representation. See posix_strtold().
    81  *
     78 *
    8279 * @param nptr
    8380 * @param endptr
     
    8683float posix_strtof(const char *restrict nptr, char **restrict endptr)
    8784{
    88         return (float) posix_strtold(nptr, endptr);
     85        // TODO
     86        not_implemented();
    8987}
    9088
    9189/**
    92  * Converts a string representation of a floating-point number to
    93  * its native representation. See posix_strtold().
    94  *
     90 *
    9591 * @param nptr
    9692 * @param endptr
     
    9995double posix_strtod(const char *restrict nptr, char **restrict endptr)
    10096{
    101         return (double) posix_strtold(nptr, endptr);
     97        // TODO
     98        not_implemented();
     99}
     100
     101/**
     102 *
     103 * @param nptr
     104 * @param endptr
     105 * @return
     106 */
     107long double posix_strtold(const char *restrict nptr, char **restrict endptr)
     108{
     109        // TODO
     110        not_implemented();
    102111}
    103112
  • uspace/lib/posix/stdlib.h

    r0ffbed9 rf48b637  
    4343#endif
    4444
    45 /* Process Termination */
    4645#undef EXIT_FAILURE
    4746#define EXIT_FAILURE 1
    4847#undef EXIT_SUCCESS
    4948#define EXIT_SUCCESS 0
     49
     50#define _exit exit
    5051#define _Exit exit
    5152
    5253/* Array Sort Function */
    53 extern void posix_qsort(void *array, size_t count, size_t size,
    54     int (*compare)(const void *, const void *));
     54extern void posix_qsort(void *array, size_t count, size_t size, int (*compare)(const void *, const void *));
    5555
    5656/* Environment Access */
     
    6060extern char *posix_realpath(const char *restrict name, char *restrict resolved);
    6161
    62 /* Floating Point Conversion */
     62/* decimal to native floating point conversion */
    6363extern float posix_strtof(const char *restrict nptr, char **restrict endptr);
    6464extern double posix_strtod(const char *restrict nptr, char **restrict endptr);
    6565extern long double posix_strtold(const char *restrict nptr, char **restrict endptr);
    6666
    67 /* Integer Conversion */
     67/* decimal to native integer conversion */
    6868extern int posix_atoi(const char *str);
    6969
  • uspace/lib/posix/string.c

    r0ffbed9 rf48b637  
    4343#include <errno.h>
    4444
    45 /**
    46  * Defined for convenience. Returns pointer to the terminating nul character.
    47  *
    48  * @param s
    49  * @return
     45/* Defined for convenience. Returns pointer to the terminating nul character.
    5046 */
    5147static char *strzero(const char *s)
    5248{
    53         while (*s != '\0') {
    54                 s++;
    55         }
    56 
    57         return (char *) s;
    58 }
    59 
    60 /**
    61  * Returns true if s2 is a prefix of s1.
    62  *
    63  * @param s1
    64  * @param s2
    65  * @return
     49        while (*s != '\0')
     50                s ++;
     51
     52        return (char*) s;
     53}
     54
     55/* Returns true if s2 is a prefix of s1.
    6656 */
    6757static bool begins_with(const char *s1, const char *s2)
    6858{
    6959        while (*s1 == *s2 && *s2 != '\0') {
    70                 s1++;
    71                 s2++;
     60                s1 ++;
     61                s2 ++;
    7262        }
    7363       
     
    7666}
    7767
    78 /**
    79  * The same as strpbrk, except it returns pointer to the nul terminator
     68/* The same as strpbrk, except it returns pointer to the nul terminator
    8069 * if no occurence is found.
    81  *
    82  * @param s1
    83  * @param s2
    84  * @return
    8570 */
    8671static char *strpbrk_null(const char *s1, const char *s2)
    8772{
    8873        while (!posix_strchr(s2, *s1)) {
    89                 ++s1;
     74                ++ s1;
    9075        }
    9176       
     
    9782 * @param dest
    9883 * @param src
    99  * @return
     84 * @return dest
    10085 */
    10186char *posix_strcpy(char *dest, const char *src)
     
    11095 * @param src
    11196 * @param n
    112  * @return
     97 * @return dest
    11398 */
    11499char *posix_strncpy(char *dest, const char *src, size_t n)
     
    129114        assert(src != NULL);
    130115
    131         for (size_t i = 0; ; ++i) {
     116        for (size_t i = 0; ; ++ i) {
    132117                dest[i] = src[i];
    133118               
     
    154139        assert(src != NULL);
    155140
    156         for (size_t i = 0; i < n; ++i) {
     141        for (size_t i = 0; i < n; ++ i) {
    157142                dest[i] = src[i];
    158143       
     
    162147                if (src[i] == '\0') {
    163148                        char *result = &dest[i];
    164                         for (++i; i < n; ++i) {
     149                        for (++ i; i < n; ++ i) {
    165150                                dest[i] = '\0';
    166151                        }
     
    176161 * @param dest
    177162 * @param src
    178  * @return
     163 * @return dest
    179164 */
    180165char *posix_strcat(char *dest, const char *src)
     
    192177 * @param src
    193178 * @param n
    194  * @return
     179 * @return dest
    195180 */
    196181char *posix_strncat(char *dest, const char *src, size_t n)
     
    213198 * @return Pointer to the first byte after c in dest if found, NULL otherwise.
    214199 */
    215 void *posix_memccpy(void *dest, const void *src, int c, size_t n)
     200void *posix_memccpy(void *restrict dest, const void *restrict src, int c, size_t n)
    216201{
    217202        assert(dest != NULL);
     
    221206        const unsigned char* bsrc = src;
    222207       
    223         for (size_t i = 0; i < n; ++i) {
     208        for (size_t i = 0; i < n; ++ i) {
    224209                bdest[i] = bsrc[i];
    225210       
     
    272257 * @param n
    273258 * @return Difference of the first pair of inequal bytes,
    274  *     or 0 if areas have the same content
     259 *          or 0 if areas have the same content
    275260 */
    276261int posix_memcmp(const void *mem1, const void *mem2, size_t n)
     
    282267        const unsigned char *s2 = mem2;
    283268       
    284         for (size_t i = 0; i < n; ++i) {
     269        for (size_t i = 0; i < n; ++ i) {
    285270                if (s1[i] != s2[i]) {
    286271                        return s2[i] - s1[i];
     
    317302        assert(s2 != NULL);
    318303
    319         for (size_t i = 0; i < n; ++i) {
     304        for (size_t i = 0; i < n; ++ i) {
    320305                if (s1[i] != s2[i]) {
    321306                        return s2[i] - s1[i];
     
    342327        const unsigned char *s = mem;
    343328       
    344         for (size_t i = 0; i < n; ++i) {
     329        for (size_t i = 0; i < n; ++ i) {
    345330                if (s[i] == (unsigned char) c) {
    346331                        return (void *) &s[i];
     
    361346       
    362347        /* special handling for the case that zero is searched for */
    363         if (c == '\0') {
     348        if (c == '\0')
    364349                return strzero(s);
    365         }
    366350       
    367351        /* otherwise just loop through the string until found */
    368352        while (*s != (char) c) {
    369                 if (*s == '\0') {
     353                if (*s == '\0')
    370354                        return NULL;
    371                 }
    372 
    373                 s++;
     355
     356                s ++;
    374357        }
    375358       
     
    391374        /* the same as in strchr, except it loops in reverse direction */
    392375        while (*ptr != (char) c) {
    393                 if (ptr == s) {
     376                if (ptr == s)
    394377                        return NULL;
    395                 }
    396 
    397                 ptr++;
     378
     379                ptr ++;
    398380        }
    399381
     
    443425
    444426        const char *ptr;
    445         for (ptr = s1; *ptr != '\0'; ++ptr) {
    446                 if (!posix_strchr(s2, *ptr)) {
     427        for (ptr = s1; *ptr != '\0'; ++ ptr) {
     428                if (!posix_strchr(s2, *ptr))
    447429                        break;
    448                 }
    449430        }
    450431        return ptr - s1;
     
    463444
    464445        /* special case - needle is an empty string */
    465         if (*s2 == '\0') {
     446        if (*s2 == '\0')
    466447                return (char *) s1;
    467         }
    468448
    469449        // TODO: use faster algorithm
    470450        /* check for prefix from every position - quadratic complexity */
    471451        while (*s1 != '\0') {
    472                 if (begins_with(s1, s2)) {
     452                if (begins_with(s1, s2))
    473453                        return (char *) s1;
    474                 }
    475454               
    476                 s1++;
     455                s1 ++;
    477456        }
    478457       
     
    510489        size_t len = posix_strlen(s2);
    511490
    512         if (n > len) {
     491        if (n > len)
    513492                posix_strcpy(s1, s2);
    514         }
    515493
    516494        return len;
     
    525503{
    526504        /* uses function from libc, we just have to negate errno
    527          * (POSIX uses positive errorcodes, HelenOS has negative)
    528          */
    529         return (char *) str_error(-errnum);
     505           (POSIX uses positive errorcodes, HelenOS has negative) */
     506        return (char *) str_error (-errnum);
    530507}
    531508
     
    533510 *
    534511 * @param errnum Error code
    535  * @param buf Buffer to store a human readable string to
    536  * @param bufsz Size of buffer pointed to by buf
     512 * @param buf    Buffer to store a human readable string to
     513 * @param bufsz  Size of buffer pointed to by buf
    537514 * @return
    538515 */
     
    575552        assert(s != NULL);
    576553       
    577         for (size_t sz = 0; sz < n; ++sz) {
     554        for (size_t sz = 0; sz < n; ++ sz) {
    578555               
    579556                if (s[sz] == '\0') {
  • uspace/lib/posix/string.h

    r0ffbed9 rf48b637  
    130130        #define strerror posix_strerror
    131131        #define strerror_r posix_strerror_r
    132         #define strsignal(i) ((char *) "SIGNonSense: There are no signals in HelenOS.")
     132        #define strsignal(i) ((char*) "SIGNonSense: There are no signals in HelenOS.")
    133133
    134134        #define strlen posix_strlen
  • uspace/lib/posix/strings.c

    r0ffbed9 rf48b637  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
    3  * Copyright (c) 2011 Petr Koupy
    43 * All rights reserved.
    54 *
     
    3433 */
    3534
    36 #define LIBPOSIX_INTERNAL
     35#define POSIX_INTERNAL
    3736
    38 #include "internal/common.h"
     37#include "common.h"
    3938#include "strings.h"
    4039#include "string.h"
    41 #include "ctype.h"
    4240
    43 /**
    44  *
    45  * @param i
    46  * @return
    47  */
    4841int posix_ffs(int i)
    4942{
     
    5245}
    5346
    54 /**
    55  *
    56  * @param s1
    57  * @param s2
    58  * @return
    59  */
    6047int posix_strcasecmp(const char *s1, const char *s2)
    6148{
    62         return posix_strncasecmp(s1, s2, STR_NO_LIMIT);
     49        // TODO
     50        not_implemented();
    6351}
    6452
    65 /**
    66  *
    67  * @param s1
    68  * @param s2
    69  * @param n
    70  * @return
    71  */
    7253int posix_strncasecmp(const char *s1, const char *s2, size_t n)
    7354{
    74         for (size_t i = 0; i < n; ++i) {
    75                 int cmp = tolower(s1[i]) - tolower(s2[i]);
    76                 if (cmp != 0) {
    77                         return cmp;
    78                 }
    79                
    80                 if (s1[i] == 0) {
    81                         return 0;
    82                 }
    83         }
    84        
    85         return 0;
     55        // TODO
     56        not_implemented();
    8657}
    8758
    88 /**
    89  *
    90  * @param mem1
    91  * @param mem2
    92  * @param n
    93  * @return
    94  */
    9559int posix_bcmp(const void *mem1, const void *mem2, size_t n)
    9660{
     
    9963}
    10064
    101 /**
    102  *
    103  * @param dest
    104  * @param src
    105  * @param n
    106  */
    10765void posix_bcopy(const void *dest, void *src, size_t n)
    10866{
     
    11169}
    11270
    113 /**
    114  *
    115  * @param mem
    116  * @param n
    117  */
    11871void posix_bzero(void *mem, size_t n)
    11972{
     
    12275}
    12376
    124 /**
    125  *
    126  * @param s
    127  * @param c
    128  * @return
    129  */
    13077char *posix_index(const char *s, int c)
    13178{
     
    13380}
    13481
    135 /**
    136  *
    137  * @param s
    138  * @param c
    139  * @return
    140  */
    14182char *posix_rindex(const char *s, int c)
    14283{
     
    14687/** @}
    14788 */
     89
  • uspace/lib/posix/strings.h

    r0ffbed9 rf48b637  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
    3  * Copyright (c) 2011 Petr Koupy
    43 * All rights reserved.
    54 *
     
    3736#define POSIX_STRINGS_H_
    3837
    39 /* Search Functions */
    40 extern int posix_ffs(int i);
     38extern int posix_ffs(int);
    4139
    42 /* String/Array Comparison */
    43 extern int posix_strcasecmp(const char *s1, const char *s2);
    44 extern int posix_strncasecmp(const char *s1, const char *s2, size_t n);
     40extern int posix_strcasecmp(const char *, const char *);
     41extern int posix_strncasecmp(const char *, const char *, size_t);
    4542
    4643/* TODO: not implemented due to missing locale.h
     
    5047 */
    5148
     49
    5250/* Legacy Functions */
    53 extern int posix_bcmp(const void *mem1, const void *mem2, size_t n);
    54 extern void posix_bcopy(const void *dest, void *src, size_t n);
    55 extern void posix_bzero(void *mem, size_t n);
    56 extern char *posix_index(const char *s, int c);
    57 extern char *posix_rindex(const char *s, int c);
     51
     52extern int posix_bcmp(const void *, const void *, size_t);
     53extern void posix_bcopy(const void *, void *, size_t);
     54extern void posix_bzero(void *, size_t);
     55extern char *posix_index(const char *, int);
     56extern char *posix_rindex(const char *, int);
    5857
    5958#ifndef LIBPOSIX_INTERNAL
    6059        #define ffs posix_ffs
    61 
    6260        #define strcasecmp posix_strcasecmp
    6361        #define strncasecmp posix_strncasecmp
    64 
     62       
    6563        #define bcmp posix_bcmp
    6664        #define bcopy posix_bcopy
  • uspace/lib/posix/sys/stat.c

    r0ffbed9 rf48b637  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
    3  * Copyright (c) 2011 Petr Koupy
    43 * All rights reserved.
    54 *
     
    2827 */
    2928
    30 /** @addtogroup libposix
    31  * @{
    32  */
    33 /** @file
    34  */
    35 
    3629#define LIBPOSIX_INTERNAL
    3730
    3831#include "stat.h"
    39 #include "../internal/common.h"
    4032#include <mem.h>
    4133
    42 /**
    43  * Convert HelenOS stat struct into POSIX stat struct (if possible)
    44  *
    45  * @param dest
    46  * @param src
     34/* Convert HelenOS stat struct into POSIX stat struct (if possible)
    4735 */
    48 static void stat_to_posix(struct posix_stat *dest, struct stat *src)
     36static void stat_to_posix (struct posix_stat *dest, struct stat *src)
    4937{
    5038        memset(dest, 0, sizeof(struct posix_stat));
     
    5442        /* HelenOS doesn't support permissions, so we set them all */
    5543        dest->st_mode = S_IRWXU | S_IRWXG | S_IRWXO;
    56         if (src->is_file) {
     44        if (src->is_file)
    5745                dest->st_mode |= S_IFREG;
    58         }
    59         if (src->is_directory) {
     46        if (src->is_directory)
    6047                dest->st_mode |= S_IFDIR;
    61         }
    6248       
    6349        dest->st_nlink = src->lnkcnt;
     
    6551}
    6652
    67 /**
    68  *
    69  * @param fd
    70  * @param st
    71  * @return
    72  */
    7353int posix_fstat(int fd, struct posix_stat *st)
    7454{
     
    8262}
    8363
    84 /**
    85  *
    86  * @param path
    87  * @param st
    88  * @return
    89  */
    90 int posix_lstat(const char *restrict path, struct posix_stat *restrict st)
    91 {
    92         // TODO
    93         not_implemented();
    94 }
    95 
    96 /**
    97  *
    98  * @param path
    99  * @param st
    100  * @return
    101  */
    10264int posix_stat(const char *path, struct posix_stat *st)
    10365{
     
    11173}
    11274
    113 /**
    114  *
    115  * @param path
    116  * @param mode
    117  * @return
    118  */
    119 int posix_chmod(const char *path, mode_t mode)
    120 {
    121         // TODO
    122         not_implemented();
    123 }
    124 
    125 /**
    126  *
    127  * @param mask
    128  * @return
    129  */
    130 mode_t posix_umask(mode_t mask)
    131 {
    132         // TODO
    133         not_implemented();
    134 }
    135 
    136 /** @}
    137  */
  • uspace/lib/posix/sys/stat.h

    r0ffbed9 rf48b637  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
    3  * Copyright (c) 2011 Petr Koupy
    43 * All rights reserved.
    54 *
     
    2827 */
    2928
    30 /** @addtogroup libposix
    31  * @{
    32  */
    33 /** @file
    34  */
    35 
    3629#ifndef POSIX_SYS_STAT_H_
    3730#define POSIX_SYS_STAT_H_
    3831
    3932#include "../libc/sys/stat.h"
    40 #include "types.h"
    41 #include "../time.h"
    42 #include <ipc/devmap.h>
    43 #include <task.h>
    44 
    45 typedef devmap_handle_t posix_dev_t;
    46 typedef task_id_t posix_pid_t;
     33#include "time.h"
    4734
    4835/* values are the same as on Linux */
    49 
    50 #undef S_IFMT
    51 #undef S_IFSOCK
    52 #undef S_IFLNK
    53 #undef S_IFREG
    54 #undef S_IFBLK
    55 #undef S_IFDIR
    56 #undef S_IFCHR
    57 #undef S_IFIFO
    5836#define S_IFMT     0170000   /* all file types */
    5937#define S_IFSOCK   0140000   /* socket */
     
    6543#define S_IFIFO    0010000   /* FIFO */
    6644
    67 #undef S_ISUID
    68 #undef S_ISGID
    69 #undef S_ISVTX
    7045#define S_ISUID    0004000   /* SUID */
    7146#define S_ISGID    0002000   /* SGID */
    7247#define S_ISVTX    0001000   /* sticky */
    7348
    74 #undef S_IRWXU
    75 #undef S_IRUSR
    76 #undef S_IWUSR
    77 #undef S_IXUSR
    7849#define S_IRWXU    00700     /* owner permissions */
    7950#define S_IRUSR    00400
     
    8152#define S_IXUSR    00100
    8253
    83 #undef S_IRWXG
    84 #undef S_IRGRP
    85 #undef S_IWGRP
    86 #undef S_IXGRP
    8754#define S_IRWXG    00070     /* group permissions */
    8855#define S_IRGRP    00040
     
    9057#define S_IXGRP    00010
    9158
    92 #undef S_IRWXO
    93 #undef S_IROTH
    94 #undef S_IWOTH
    95 #undef S_IXOTH
    9659#define S_IRWXO    00007     /* other permissions */
    9760#define S_IROTH    00004
     
    9962#define S_IXOTH    00001
    10063
    101 #undef S_ISREG
    102 #undef S_ISDIR
    103 #undef S_ISCHR
    104 #undef S_ISBLK
    105 #undef S_ISFIFO
    106 #undef S_ISLNK
    107 #undef S_ISSOCK
    10864#define S_ISREG(m) ((m & S_IFREG) != 0)
    10965#define S_ISDIR(m) ((m & S_IFDIR) != 0)
     
    11167#define S_ISBLK(m) ((m & S_IFBLK) != 0)
    11268#define S_ISFIFO(m) ((m & S_IFIFO) != 0)
    113 #define S_ISLNK(m) ((m & S_IFLNK) != 0) /* symbolic link? (Not in POSIX.1-1996.) */
     69#define S_ISLNK(m) ((m & S_IFLNK) != 0)   /* symbolic link? (Not in POSIX.1-1996.) */
    11470#define S_ISSOCK(m) ((m & S_IFSOCK) != 0) /* socket? (Not in POSIX.1-1996.) */
     71
     72typedef devmap_handle_t dev_t;
     73typedef unsigned int ino_t;
     74typedef unsigned int nlink_t;
     75typedef unsigned int uid_t;
     76typedef unsigned int gid_t;
     77typedef aoff64_t off_t;
     78typedef unsigned int blksize_t;
     79typedef unsigned int blkcnt_t;
    11580
    11681struct posix_stat {
    11782        struct stat sys_stat;
    11883
    119         posix_dev_t     st_dev;     /* ID of device containing file */
    120         posix_ino_t     st_ino;     /* inode number */
    121         mode_t          st_mode;    /* protection */
    122         posix_nlink_t   st_nlink;   /* number of hard links */
    123         posix_uid_t     st_uid;     /* user ID of owner */
    124         posix_gid_t     st_gid;     /* group ID of owner */
    125         posix_dev_t     st_rdev;    /* device ID (if special file) */
    126         posix_off_t     st_size;    /* total size, in bytes */
    127         posix_blksize_t st_blksize; /* blocksize for file system I/O */
    128         posix_blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
    129         time_t          st_atime;   /* time of last access */
    130         time_t          st_mtime;   /* time of last modification */
    131         time_t          st_ctime;   /* time of last status change */
     84        dev_t     st_dev;     /* ID of device containing file */
     85        ino_t     st_ino;     /* inode number */
     86        mode_t    st_mode;    /* protection */
     87        nlink_t   st_nlink;   /* number of hard links */
     88        uid_t     st_uid;     /* user ID of owner */
     89        gid_t     st_gid;     /* group ID of owner */
     90        dev_t     st_rdev;    /* device ID (if special file) */
     91        off_t     st_size;    /* total size, in bytes */
     92        blksize_t st_blksize; /* blocksize for file system I/O */
     93        blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
     94        time_t    st_atime;   /* time of last access */
     95        time_t    st_mtime;   /* time of last modification */
     96        time_t    st_ctime;   /* time of last status change */
    13297};
    13398
    134 extern int posix_fstat(int fd, struct posix_stat *st);
    135 extern int posix_lstat(const char *restrict path, struct posix_stat *restrict st);
    136 extern int posix_stat(const char *restrict path, struct posix_stat *restrict st);
    137 extern int posix_chmod(const char *path, mode_t mode);
    138 extern mode_t posix_umask(mode_t mask);
     99extern int posix_fstat(int, struct posix_stat *);
     100extern int posix_stat(const char *, struct posix_stat *);
    139101
    140102#ifndef LIBPOSIX_INTERNAL
    141         #define dev_t posix_dev_t
    142         #define pid_t posix_pid_t
    143103        #define fstat posix_fstat
    144         #define lstat posix_lstat
    145104        #define stat posix_stat
    146         #define chmod posix_chmod
    147         #define umask posix_umask
    148105#endif
    149106
    150107#endif /* POSIX_SYS_STAT_H */
    151108
    152 /** @}
    153  */
  • uspace/lib/posix/sys/types.h

    r0ffbed9 rf48b637  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
    3  * Copyright (c) 2011 Petr Koupy
    43 * All rights reserved.
    54 *
     
    2827 */
    2928
    30 /** @addtogroup libposix
    31  * @{
    32  */
    33 /** @file
    34  */
    35 
    3629#ifndef POSIX_SYS_TYPES_H_
    3730#define POSIX_SYS_TYPES_H_
    3831
    3932#include "../libc/sys/types.h"
     33#include <task.h>
    4034
    41 typedef unsigned int posix_ino_t;
    42 typedef unsigned int posix_nlink_t;
    43 typedef unsigned int posix_uid_t;
    44 typedef unsigned int posix_gid_t;
    45 typedef aoff64_t posix_off_t;
    46 typedef unsigned int posix_blksize_t;
    47 typedef unsigned int posix_blkcnt_t;
    48 
    49 #ifndef LIBPOSIX_INTERNAL
    50         #define ino_t posix_ino_t
    51         #define nlink_t posix_nlink_t
    52         #define uid_t posix_uid_t
    53         #define gid_t posix_gid_t
    54         #define off_t posix_off_t
    55         #define blksize_t posix_blksize_t
    56         #define blkcnt_t posix_blkcnt_t
    57 #endif
     35typedef task_id_t pid_t;
    5836
    5937#endif /* POSIX_SYS_TYPES_H_ */
    6038
    61 /** @}
    62  */
  • uspace/lib/posix/time.c

    r0ffbed9 rf48b637  
    3636#define LIBPOSIX_INTERNAL
    3737
    38 #include "internal/common.h"
    3938#include "time.h"
    4039
     
    8483{
    8584        // TODO
    86         not_implemented();
     85        return 0;
    8786}
    8887
  • uspace/lib/posix/unistd.c

    r0ffbed9 rf48b637  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
    3  * Copyright (c) 2011 Petr Koupy
    43 * All rights reserved.
    54 *
     
    2827 */
    2928
    30 /** @addtogroup libposix
    31  * @{
    32  */
    33 /** @file
    34  */
    35 
    36 #define LIBPOSIX_INTERNAL
    37 
    38 #include "internal/common.h"
    3929#include "unistd.h"
    4030
    41 /**
    42  * Dummy function. Always returns false, because there is no easy way to find
    43  * out under HelenOS.
    44  *
    45  * @param fd
    46  * @return Always false.
    47  */
    48 int posix_isatty(int fd)
    49 {
    50         return false;
     31int isatty(int fd) {
     32        // TODO
     33        return 0;
    5134}
    5235
    53 /**
    54  *
    55  * @return
    56  */
    57 posix_uid_t posix_getuid(void)
    58 {
    59         // TODO
    60         not_implemented();
    61 }
    62 
    63 /**
    64  *
    65  * @return
    66  */
    67 posix_gid_t posix_getgid(void)
    68 {
    69         // TODO
    70         not_implemented();
    71 }
    72 
    73 /**
    74  *
    75  * @param path
    76  * @param amode
    77  * @return
    78  */
    79 int posix_access(const char *path, int amode)
    80 {
    81         // TODO
    82         not_implemented();
    83 }
    84 
    85 /**
    86  *
    87  * @param name
    88  * @return
    89  */
    90 long posix_sysconf(int name)
    91 {
    92         // TODO
    93         not_implemented();
    94 }
    95 
    96 /** @}
    97  */
  • uspace/lib/posix/unistd.h

    r0ffbed9 rf48b637  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
    3  * Copyright (c) 2011 Petr Koupy
    43 * All rights reserved.
    54 *
     
    2726 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2827 */
    29 
    30 /** @addtogroup libposix
    31  * @{
    32  */
    33 /** @file
    34  */
    35 
     28 
    3629#ifndef POSIX_UNISTD_H_
    3730#define POSIX_UNISTD_H_
    3831
    3932#include "libc/unistd.h"
    40 #include "sys/types.h"
    4133
    42 /* Process Termination */
    43 #define _exit exit
     34/* #include <getopt.h> */
    4435
    45 /* Option Arguments */
    4636extern char *optarg;
    4737extern int optind, opterr, optopt;
    4838extern int getopt(int, char * const [], const char *);
    4939
    50 /* Identifying Terminals */
    51 extern int posix_isatty(int fd);
     40extern int isatty(int fd);
    5241
    53 /* Process Identification */
    5442#define getpid task_get_id
    55 extern posix_uid_t posix_getuid(void);
    56 extern posix_gid_t posix_getgid(void);
    5743
    58 /* Standard Streams */
    59 #undef STDIN_FILENO
    6044#define STDIN_FILENO (fileno(stdin))
    61 #undef STDOUT_FILENO
    6245#define STDOUT_FILENO (fileno(stdout))
    63 #undef STDERR_FILENO
    6446#define STDERR_FILENO (fileno(stderr))
    65 
    66 /* File Accessibility */
    67 #undef F_OK
    68 #undef X_OK
    69 #undef W_OK
    70 #undef R_OK
    71 #define F_OK 0 /* Test for existence. */
    72 #define X_OK 1 /* Test for execute permission. */
    73 #define W_OK 2 /* Test for write permission. */
    74 #define R_OK 4 /* Test for read permission. */
    75 extern int posix_access(const char *path, int amode);
    76 
    77 /* System Parameters */
    78 enum {
    79         _SC_PHYS_PAGES,
    80         _SC_AVPHYS_PAGES,
    81         _SC_PAGESIZE,
    82         _SC_CLK_TCK
    83 };
    84 extern long posix_sysconf(int name);
    85 
    86 #ifndef LIBPOSIX_INTERNAL
    87         #define isatty posix_isatty
    88 
    89         #define getuid posix_getuid
    90         #define getgid posix_getgid
    91 
    92         #define access posix_access
    93 
    94         #define sysconf posix_sysconf
    95 #endif
    9647
    9748#endif /* POSIX_UNISTD_H_ */
    9849
    99 /** @}
    100  */
Note: See TracChangeset for help on using the changeset viewer.