Changeset 4f4b4e7 in mainline


Ignore:
Timestamp:
2011-06-15T23:38:45Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b08ef1fd
Parents:
ab547063
Message:

Coding style and file structure unified.
_exit moved to unistd.h.

Location:
uspace/lib/posix
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/common.h

    rab547063 r4f4b4e7  
    2727 */
    2828
     29/** @addtogroup libposix
     30 * @{
     31 */
     32/** @file
     33 */
     34
    2935#ifndef LIBPOSIX_COMMON_H_
    3036#define LIBPOSIX_COMMON_H_
     
    3339#include <stdlib.h>
    3440
    35 #define not_implemented() (fprintf(stderr, "Function %s() in file %s at line %d is not implemented\n", __func__, __FILE__, __LINE__), abort())
     41#define not_implemented() (fprintf(stderr, \
     42    "Function %s() in file %s at line %d is not implemented\n", \
     43    __func__, __FILE__, __LINE__), abort())
    3644
    3745#endif /* LIBPOSIX_COMMON_H_ */
    3846
     47/** @}
     48 */
  • uspace/lib/posix/ctype.c

    rab547063 r4f4b4e7  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
     3 * Copyright (c) 2011 Petr Koupy
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
     30/** @addtogroup libposix
     31 * @{
     32 */
     33/** @file
     34 */
     35
     36#define POSIX_INTERNAL
     37
    2938#include "ctype.h"
    3039
    31 int isxdigit(int ch)
     40/**
     41 *
     42 * @param ch
     43 * @return
     44 */
     45int posix_isxdigit(int ch)
    3246{
    3347        return isdigit(ch) ||
    34                (ch >= 'a' && ch <= 'f') ||
    35                (ch >= 'A' && ch <= 'F');
     48            (ch >= 'a' && ch <= 'f') ||
     49            (ch >= 'A' && ch <= 'F');
    3650}
    3751
     52/** @}
     53 */
  • uspace/lib/posix/ctype.h

    rab547063 r4f4b4e7  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
     3 * Copyright (c) 2011 Petr Koupy
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
     30/** @addtogroup libposix
     31 * @{
     32 */
     33/** @file
     34 */
     35
    2936#ifndef POSIX_CTYPE_H_
    3037#define POSIX_CTYPE_H_
     
    3239#include "libc/ctype.h"
    3340
    34 extern int isxdigit(int ch);
     41/* Classification of Characters */
     42extern int posix_isxdigit(int ch);
     43
     44#ifndef POSIX_INTERNAL
     45        #define isxdigit posix_isxdigit
     46#endif
    3547
    3648#endif /* POSIX_CTYPE_H_ */
    3749
     50/** @}
     51 */
  • uspace/lib/posix/signal.h

    rab547063 r4f4b4e7  
    2727 */
    2828
     29/** @addtogroup libposix
     30 * @{
     31 */
     32/** @file
     33 */
     34
    2935#ifndef POSIX_SIGNAL_H_
    3036#define POSIX_SIGNAL_H_
    3137
    32 #include <errno.h>
     38#include "libc/errno.h"
    3339
    3440/* HelenOS doesn't have signals, so calls to functions of this header
     
    4147 */
    4248
     49#undef SIG_DFL
    4350#define SIG_DFL ((void (*)(int)) 0)
     51#undef SIG_ERR
    4452#define SIG_ERR ((void (*)(int)) 0)
     53#undef SIG_IGN
    4554#define SIG_IGN ((void (*)(int)) 0)
    4655
    4756#define signal(sig,func) (errno = ENOTSUP, SIG_ERR)
    48 #define raise(sig) ((int)-1)
     57#define raise(sig) ((int) -1)
    4958
    50 typedef int sig_atomic_t;
     59typedef int posix_sig_atomic_t;
    5160
    5261/* full POSIX set */
     
    8291};
    8392
     93#ifndef POSIX_INTERNAL
     94        #define sig_atomic_t posix_sig_atomic_t
     95#endif
     96
    8497#endif /* POSIX_SIGNAL_H_ */
    8598
     99/** @}
     100 */
  • uspace/lib/posix/stdio.c

    rab547063 r4f4b4e7  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
     3 * Copyright (c) 2011 Petr Koupy
    34 * All rights reserved.
    45 *
     
    3637
    3738#include <assert.h>
    38 #include "errno.h"
     39#include <errno.h>
     40
    3941#include "common.h"
    4042#include "stdio.h"
    4143#include "string.h"
     44
    4245/* not the best of solutions, but freopen will eventually
    43    need to be implemented in libc anyway */
     46 * need to be implemented in libc anyway
     47 */
    4448#include "../c/generic/private/stdio.h"
    4549
    46 FILE *posix_freopen(const char *restrict filename,
    47                     const char *restrict mode,
    48                     FILE *restrict stream)
     50/**
     51 *
     52 * @param filename
     53 * @param mode
     54 * @param stream
     55 * @return
     56 */
     57FILE *posix_freopen(
     58    const char *restrict filename,
     59    const char *restrict mode,
     60    FILE *restrict stream)
    4961{
    5062        assert(mode != NULL);
     
    5567               
    5668                /* print error to stderr as well, to avoid hard to find problems
    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");
     69                 * with buggy apps that expect this to work
     70                 */
     71                fprintf(stderr,
     72                    "ERROR: Application wants to use freopen() to change mode of opened stream.\n"
     73                    "       libposix does not support that yet, the application may function improperly.\n");
    6074                errno = ENOTSUP;
    6175                return NULL;
     
    6882        }
    6983        memcpy(copy, stream, sizeof(FILE));
    70         fclose(copy);   /* copy is now freed */
     84        fclose(copy); /* copy is now freed */
    7185       
    72         copy = fopen(filename, mode);         /* open new stream */
     86        copy = fopen(filename, mode); /* open new stream */
    7387        if (copy == NULL) {
    7488                /* fopen() sets errno */
     
    87101}
    88102
     103/**
     104 *
     105 * @param s
     106 */
    89107void posix_perror(const char *s)
    90108{
     
    95113/** @}
    96114 */
    97 
  • uspace/lib/posix/stdio.h

    rab547063 r4f4b4e7  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
     3 * Copyright (c) 2011 Petr Koupy
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
     30/** @addtogroup libposix
     31 * @{
     32 */
     33/** @file
     34 */
     35
    2936#ifndef POSIX_STDIO_H_
    3037#define POSIX_STDIO_H_
     
    3239#include "libc/stdio.h"
    3340
     41/* Character Input/Output */
    3442#define putc fputc
    3543#define getc fgetc
    3644
     45/* Opening Streams */
     46extern FILE *posix_freopen(
     47   const char *restrict filename,
     48   const char *restrict mode,
     49   FILE *restrict stream);
    3750
    38 extern FILE *posix_freopen(const char *restrict filename,
    39                            const char *restrict mode,
    40                            FILE *restrict stream);
    41 
     51/* Error Messages */
    4252extern void posix_perror(const char *s);
    4353
    4454#ifndef POSIX_INTERNAL
    4555        #define freopen posix_freopen
     56
    4657        #define perror posix_perror
    4758#endif
     
    4960#endif /* POSIX_STDIO_H_ */
    5061
     62/** @}
     63 */
  • uspace/lib/posix/stdlib.c

    rab547063 r4f4b4e7  
    4646 * @param compare
    4747 */
    48 void posix_qsort(void *array, size_t count, size_t size, int (*compare)(const void *, const void *))
     48void posix_qsort(void *array, size_t count, size_t size,
     49    int (*compare)(const void *, const void *))
    4950{
    5051        // TODO
  • uspace/lib/posix/stdlib.h

    rab547063 r4f4b4e7  
    4343#endif
    4444
     45/* Process Termination */
    4546#undef EXIT_FAILURE
    4647#define EXIT_FAILURE 1
    4748#undef EXIT_SUCCESS
    4849#define EXIT_SUCCESS 0
    49 
    50 #define _exit exit
    5150#define _Exit exit
    5251
    5352/* Array Sort Function */
    54 extern void posix_qsort(void *array, size_t count, size_t size, int (*compare)(const void *, const void *));
     53extern void posix_qsort(void *array, size_t count, size_t size,
     54    int (*compare)(const void *, const void *));
    5555
    5656/* Environment Access */
     
    6060extern char *posix_realpath(const char *restrict name, char *restrict resolved);
    6161
    62 /* decimal to native floating point conversion */
     62/* 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 /* decimal to native integer conversion */
     67/* Integer Conversion */
    6868extern int posix_atoi(const char *str);
    6969
  • uspace/lib/posix/string.c

    rab547063 r4f4b4e7  
    4343#include <errno.h>
    4444
    45 /* Defined for convenience. Returns pointer to the terminating nul character.
     45/**
     46 * Defined for convenience. Returns pointer to the terminating nul character.
     47 *
     48 * @param s
     49 * @return
    4650 */
    4751static char *strzero(const char *s)
    4852{
    49         while (*s != '\0')
    50                 s ++;
    51 
    52         return (char*) s;
    53 }
    54 
    55 /* Returns true if s2 is a prefix of s1.
     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
    5666 */
    5767static bool begins_with(const char *s1, const char *s2)
    5868{
    5969        while (*s1 == *s2 && *s2 != '\0') {
    60                 s1 ++;
    61                 s2 ++;
     70                s1++;
     71                s2++;
    6272        }
    6373       
     
    6676}
    6777
    68 /* The same as strpbrk, except it returns pointer to the nul terminator
     78/**
     79 * The same as strpbrk, except it returns pointer to the nul terminator
    6980 * if no occurence is found.
     81 *
     82 * @param s1
     83 * @param s2
     84 * @return
    7085 */
    7186static char *strpbrk_null(const char *s1, const char *s2)
    7287{
    7388        while (!posix_strchr(s2, *s1)) {
    74                 ++ s1;
     89                ++s1;
    7590        }
    7691       
     
    8297 * @param dest
    8398 * @param src
    84  * @return dest
     99 * @return
    85100 */
    86101char *posix_strcpy(char *dest, const char *src)
     
    95110 * @param src
    96111 * @param n
    97  * @return dest
     112 * @return
    98113 */
    99114char *posix_strncpy(char *dest, const char *src, size_t n)
     
    114129        assert(src != NULL);
    115130
    116         for (size_t i = 0; ; ++ i) {
     131        for (size_t i = 0; ; ++i) {
    117132                dest[i] = src[i];
    118133               
     
    139154        assert(src != NULL);
    140155
    141         for (size_t i = 0; i < n; ++ i) {
     156        for (size_t i = 0; i < n; ++i) {
    142157                dest[i] = src[i];
    143158       
     
    147162                if (src[i] == '\0') {
    148163                        char *result = &dest[i];
    149                         for (++ i; i < n; ++ i) {
     164                        for (++i; i < n; ++i) {
    150165                                dest[i] = '\0';
    151166                        }
     
    161176 * @param dest
    162177 * @param src
    163  * @return dest
     178 * @return
    164179 */
    165180char *posix_strcat(char *dest, const char *src)
     
    177192 * @param src
    178193 * @param n
    179  * @return dest
     194 * @return
    180195 */
    181196char *posix_strncat(char *dest, const char *src, size_t n)
     
    198213 * @return Pointer to the first byte after c in dest if found, NULL otherwise.
    199214 */
    200 void *posix_memccpy(void *restrict dest, const void *restrict src, int c, size_t n)
     215void *posix_memccpy(void *dest, const void *src, int c, size_t n)
    201216{
    202217        assert(dest != NULL);
     
    206221        const unsigned char* bsrc = src;
    207222       
    208         for (size_t i = 0; i < n; ++ i) {
     223        for (size_t i = 0; i < n; ++i) {
    209224                bdest[i] = bsrc[i];
    210225       
     
    257272 * @param n
    258273 * @return Difference of the first pair of inequal bytes,
    259  *          or 0 if areas have the same content
     274 *     or 0 if areas have the same content
    260275 */
    261276int posix_memcmp(const void *mem1, const void *mem2, size_t n)
     
    267282        const unsigned char *s2 = mem2;
    268283       
    269         for (size_t i = 0; i < n; ++ i) {
     284        for (size_t i = 0; i < n; ++i) {
    270285                if (s1[i] != s2[i]) {
    271286                        return s2[i] - s1[i];
     
    302317        assert(s2 != NULL);
    303318
    304         for (size_t i = 0; i < n; ++ i) {
     319        for (size_t i = 0; i < n; ++i) {
    305320                if (s1[i] != s2[i]) {
    306321                        return s2[i] - s1[i];
     
    327342        const unsigned char *s = mem;
    328343       
    329         for (size_t i = 0; i < n; ++ i) {
     344        for (size_t i = 0; i < n; ++i) {
    330345                if (s[i] == (unsigned char) c) {
    331346                        return (void *) &s[i];
     
    346361       
    347362        /* special handling for the case that zero is searched for */
    348         if (c == '\0')
     363        if (c == '\0') {
    349364                return strzero(s);
     365        }
    350366       
    351367        /* otherwise just loop through the string until found */
    352368        while (*s != (char) c) {
    353                 if (*s == '\0')
     369                if (*s == '\0') {
    354370                        return NULL;
    355 
    356                 s ++;
     371                }
     372
     373                s++;
    357374        }
    358375       
     
    374391        /* the same as in strchr, except it loops in reverse direction */
    375392        while (*ptr != (char) c) {
    376                 if (ptr == s)
     393                if (ptr == s) {
    377394                        return NULL;
    378 
    379                 ptr ++;
     395                }
     396
     397                ptr++;
    380398        }
    381399
     
    425443
    426444        const char *ptr;
    427         for (ptr = s1; *ptr != '\0'; ++ ptr) {
    428                 if (!posix_strchr(s2, *ptr))
     445        for (ptr = s1; *ptr != '\0'; ++ptr) {
     446                if (!posix_strchr(s2, *ptr)) {
    429447                        break;
     448                }
    430449        }
    431450        return ptr - s1;
     
    444463
    445464        /* special case - needle is an empty string */
    446         if (*s2 == '\0')
     465        if (*s2 == '\0') {
    447466                return (char *) s1;
     467        }
    448468
    449469        // TODO: use faster algorithm
    450470        /* check for prefix from every position - quadratic complexity */
    451471        while (*s1 != '\0') {
    452                 if (begins_with(s1, s2))
     472                if (begins_with(s1, s2)) {
    453473                        return (char *) s1;
     474                }
    454475               
    455                 s1 ++;
     476                s1++;
    456477        }
    457478       
     
    489510        size_t len = posix_strlen(s2);
    490511
    491         if (n > len)
     512        if (n > len) {
    492513                posix_strcpy(s1, s2);
     514        }
    493515
    494516        return len;
     
    503525{
    504526        /* uses function from libc, we just have to negate errno
    505            (POSIX uses positive errorcodes, HelenOS has negative) */
    506         return (char *) str_error (-errnum);
     527         * (POSIX uses positive errorcodes, HelenOS has negative)
     528         */
     529        return (char *) str_error(-errnum);
    507530}
    508531
     
    510533 *
    511534 * @param errnum Error code
    512  * @param buf    Buffer to store a human readable string to
    513  * @param bufsz  Size of buffer pointed to by buf
     535 * @param buf Buffer to store a human readable string to
     536 * @param bufsz Size of buffer pointed to by buf
    514537 * @return
    515538 */
     
    552575        assert(s != NULL);
    553576       
    554         for (size_t sz = 0; sz < n; ++ sz) {
     577        for (size_t sz = 0; sz < n; ++sz) {
    555578               
    556579                if (s[sz] == '\0') {
  • uspace/lib/posix/string.h

    rab547063 r4f4b4e7  
    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

    rab547063 r4f4b4e7  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
     3 * Copyright (c) 2011 Petr Koupy
    34 * All rights reserved.
    45 *
     
    3940#include "string.h"
    4041
     42/**
     43 *
     44 * @param i
     45 * @return
     46 */
    4147int posix_ffs(int i)
    4248{
     
    4551}
    4652
     53/**
     54 *
     55 * @param s1
     56 * @param s2
     57 * @return
     58 */
    4759int posix_strcasecmp(const char *s1, const char *s2)
    4860{
     
    5163}
    5264
     65/**
     66 *
     67 * @param s1
     68 * @param s2
     69 * @param n
     70 * @return
     71 */
    5372int posix_strncasecmp(const char *s1, const char *s2, size_t n)
    5473{
     
    5776}
    5877
     78/**
     79 *
     80 * @param mem1
     81 * @param mem2
     82 * @param n
     83 * @return
     84 */
    5985int posix_bcmp(const void *mem1, const void *mem2, size_t n)
    6086{
     
    6389}
    6490
     91/**
     92 *
     93 * @param dest
     94 * @param src
     95 * @param n
     96 */
    6597void posix_bcopy(const void *dest, void *src, size_t n)
    6698{
     
    69101}
    70102
     103/**
     104 *
     105 * @param mem
     106 * @param n
     107 */
    71108void posix_bzero(void *mem, size_t n)
    72109{
     
    75112}
    76113
     114/**
     115 *
     116 * @param s
     117 * @param c
     118 * @return
     119 */
    77120char *posix_index(const char *s, int c)
    78121{
     
    80123}
    81124
     125/**
     126 *
     127 * @param s
     128 * @param c
     129 * @return
     130 */
    82131char *posix_rindex(const char *s, int c)
    83132{
     
    87136/** @}
    88137 */
    89 
  • uspace/lib/posix/strings.h

    rab547063 r4f4b4e7  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
     3 * Copyright (c) 2011 Petr Koupy
    34 * All rights reserved.
    45 *
     
    3637#define POSIX_STRINGS_H_
    3738
    38 extern int posix_ffs(int);
     39/* Search Functions */
     40extern int posix_ffs(int i);
    3941
    40 extern int posix_strcasecmp(const char *, const char *);
    41 extern int posix_strncasecmp(const char *, const char *, size_t);
     42/* String/Array Comparison */
     43extern int posix_strcasecmp(const char *s1, const char *s2);
     44extern int posix_strncasecmp(const char *s1, const char *s2, size_t n);
    4245
    4346/* TODO: not implemented due to missing locale.h
     
    4750 */
    4851
    49 
    5052/* Legacy Functions */
    51 
    52 extern int posix_bcmp(const void *, const void *, size_t);
    53 extern void posix_bcopy(const void *, void *, size_t);
    54 extern void posix_bzero(void *, size_t);
    55 extern char *posix_index(const char *, int);
    56 extern char *posix_rindex(const char *, int);
     53extern int posix_bcmp(const void *mem1, const void *mem2, size_t n);
     54extern void posix_bcopy(const void *dest, void *src, size_t n);
     55extern void posix_bzero(void *mem, size_t n);
     56extern char *posix_index(const char *s, int c);
     57extern char *posix_rindex(const char *s, int c);
    5758
    5859#ifndef LIBPOSIX_INTERNAL
    5960        #define ffs posix_ffs
     61
    6062        #define strcasecmp posix_strcasecmp
    6163        #define strncasecmp posix_strncasecmp
    62        
     64
    6365        #define bcmp posix_bcmp
    6466        #define bcopy posix_bcopy
  • uspace/lib/posix/sys/stat.c

    rab547063 r4f4b4e7  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
     3 * Copyright (c) 2011 Petr Koupy
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
     30/** @addtogroup libposix
     31 * @{
     32 */
     33/** @file
     34 */
     35
    2936#define LIBPOSIX_INTERNAL
    3037
     
    3239#include <mem.h>
    3340
    34 /* Convert HelenOS stat struct into POSIX stat struct (if possible)
     41/**
     42 * Convert HelenOS stat struct into POSIX stat struct (if possible)
     43 *
     44 * @param dest
     45 * @param src
    3546 */
    36 static void stat_to_posix (struct posix_stat *dest, struct stat *src)
     47static void stat_to_posix(struct posix_stat *dest, struct stat *src)
    3748{
    3849        memset(dest, 0, sizeof(struct posix_stat));
     
    4253        /* HelenOS doesn't support permissions, so we set them all */
    4354        dest->st_mode = S_IRWXU | S_IRWXG | S_IRWXO;
    44         if (src->is_file)
     55        if (src->is_file) {
    4556                dest->st_mode |= S_IFREG;
    46         if (src->is_directory)
     57        }
     58        if (src->is_directory) {
    4759                dest->st_mode |= S_IFDIR;
     60        }
    4861       
    4962        dest->st_nlink = src->lnkcnt;
     
    5164}
    5265
     66/**
     67 *
     68 * @param fd
     69 * @param st
     70 * @return
     71 */
    5372int posix_fstat(int fd, struct posix_stat *st)
    5473{
     
    6281}
    6382
     83/**
     84 *
     85 * @param path
     86 * @param st
     87 * @return
     88 */
    6489int posix_stat(const char *path, struct posix_stat *st)
    6590{
     
    7398}
    7499
     100/** @}
     101 */
  • uspace/lib/posix/sys/stat.h

    rab547063 r4f4b4e7  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
     3 * Copyright (c) 2011 Petr Koupy
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
     30/** @addtogroup libposix
     31 * @{
     32 */
     33/** @file
     34 */
     35
    2936#ifndef POSIX_SYS_STAT_H_
    3037#define POSIX_SYS_STAT_H_
     
    3441
    3542/* values are the same as on Linux */
     43
     44#undef S_IFMT
     45#undef S_IFSOCK
     46#undef S_IFLNK
     47#undef S_IFREG
     48#undef S_IFBLK
     49#undef S_IFDIR
     50#undef S_IFCHR
     51#undef S_IFIFO
    3652#define S_IFMT     0170000   /* all file types */
    3753#define S_IFSOCK   0140000   /* socket */
     
    4359#define S_IFIFO    0010000   /* FIFO */
    4460
     61#undef S_ISUID
     62#undef S_ISGID
     63#undef S_ISVTX
    4564#define S_ISUID    0004000   /* SUID */
    4665#define S_ISGID    0002000   /* SGID */
    4766#define S_ISVTX    0001000   /* sticky */
    4867
     68#undef S_IRWXU
     69#undef S_IRUSR
     70#undef S_IWUSR
     71#undef S_IXUSR
    4972#define S_IRWXU    00700     /* owner permissions */
    5073#define S_IRUSR    00400
     
    5275#define S_IXUSR    00100
    5376
     77#undef S_IRWXG
     78#undef S_IRGRP
     79#undef S_IWGRP
     80#undef S_IXGRP
    5481#define S_IRWXG    00070     /* group permissions */
    5582#define S_IRGRP    00040
     
    5784#define S_IXGRP    00010
    5885
     86#undef S_IRWXO
     87#undef S_IROTH
     88#undef S_IWOTH
     89#undef S_IXOTH
    5990#define S_IRWXO    00007     /* other permissions */
    6091#define S_IROTH    00004
     
    6293#define S_IXOTH    00001
    6394
     95#undef S_ISREG
     96#undef S_ISDIR
     97#undef S_ISCHR
     98#undef S_ISBLK
     99#undef S_ISFIFO
     100#undef S_ISLNK
     101#undef S_ISSOCK
    64102#define S_ISREG(m) ((m & S_IFREG) != 0)
    65103#define S_ISDIR(m) ((m & S_IFDIR) != 0)
     
    67105#define S_ISBLK(m) ((m & S_IFBLK) != 0)
    68106#define S_ISFIFO(m) ((m & S_IFIFO) != 0)
    69 #define S_ISLNK(m) ((m & S_IFLNK) != 0)   /* symbolic link? (Not in POSIX.1-1996.) */
     107#define S_ISLNK(m) ((m & S_IFLNK) != 0) /* symbolic link? (Not in POSIX.1-1996.) */
    70108#define S_ISSOCK(m) ((m & S_IFSOCK) != 0) /* socket? (Not in POSIX.1-1996.) */
    71109
    72 typedef devmap_handle_t dev_t;
    73 typedef unsigned int ino_t;
    74 typedef unsigned int nlink_t;
    75 typedef unsigned int uid_t;
    76 typedef unsigned int gid_t;
    77 typedef aoff64_t off_t;
    78 typedef unsigned int blksize_t;
    79 typedef unsigned int blkcnt_t;
     110typedef devmap_handle_t posix_dev_t;
     111typedef unsigned int posix_ino_t;
     112typedef unsigned int posix_nlink_t;
     113typedef unsigned int posix_uid_t;
     114typedef unsigned int posix_gid_t;
     115typedef aoff64_t posix_off_t;
     116typedef unsigned int posix_blksize_t;
     117typedef unsigned int posix_blkcnt_t;
    80118
    81119struct posix_stat {
    82120        struct stat sys_stat;
    83121
    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 */
     122        posix_dev_t     st_dev;     /* ID of device containing file */
     123        posix_ino_t     st_ino;     /* inode number */
     124        mode_t          st_mode;    /* protection */
     125        posix_nlink_t   st_nlink;   /* number of hard links */
     126        posix_uid_t     st_uid;     /* user ID of owner */
     127        posix_gid_t     st_gid;     /* group ID of owner */
     128        posix_dev_t     st_rdev;    /* device ID (if special file) */
     129        posix_off_t     st_size;    /* total size, in bytes */
     130        posix_blksize_t st_blksize; /* blocksize for file system I/O */
     131        posix_blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
     132        time_t          st_atime;   /* time of last access */
     133        time_t          st_mtime;   /* time of last modification */
     134        time_t          st_ctime;   /* time of last status change */
    97135};
    98136
    99 extern int posix_fstat(int, struct posix_stat *);
    100 extern int posix_stat(const char *, struct posix_stat *);
     137extern int posix_fstat(int fd, struct posix_stat *st);
     138extern int posix_stat(const char *path, struct posix_stat *st);
    101139
    102140#ifndef LIBPOSIX_INTERNAL
     141        #define dev_t posix_dev_t
     142        #define nlink_t posix_nlink_t
     143        #define uid_t posix_uid_t
     144        #define gid_t posix_gid_t
     145        #define off_t posix_off_t
     146        #define blksize_t posix_blksize_t
     147        #define blkcnt_t posix_blkcnt_t
     148
    103149        #define fstat posix_fstat
    104150        #define stat posix_stat
     
    107153#endif /* POSIX_SYS_STAT_H */
    108154
     155/** @}
     156 */
  • uspace/lib/posix/sys/types.h

    rab547063 r4f4b4e7  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
     3 * Copyright (c) 2011 Petr Koupy
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
     30/** @addtogroup libposix
     31 * @{
     32 */
     33/** @file
     34 */
     35
    2936#ifndef POSIX_SYS_TYPES_H_
    3037#define POSIX_SYS_TYPES_H_
     
    3340#include <task.h>
    3441
    35 typedef task_id_t pid_t;
     42typedef task_id_t posix_pid_t;
     43
     44#ifndef POSIX_INTERNAL
     45        #define pid_t posix_pid_t
     46#endif
    3647
    3748#endif /* POSIX_SYS_TYPES_H_ */
    3849
     50/** @}
     51 */
  • uspace/lib/posix/time.c

    rab547063 r4f4b4e7  
    3636#define LIBPOSIX_INTERNAL
    3737
     38#include "common.h"
    3839#include "time.h"
    3940
     
    8384{
    8485        // TODO
    85         return 0;
     86        not_implemented();
    8687}
    8788
  • uspace/lib/posix/unistd.c

    rab547063 r4f4b4e7  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
     3 * Copyright (c) 2011 Petr Koupy
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
     30/** @addtogroup libposix
     31 * @{
     32 */
     33/** @file
     34 */
     35
     36#define POSIX_INTERNAL
     37
     38#include "common.h"
    2939#include "unistd.h"
    3040
    31 int isatty(int fd) {
     41/**
     42 *
     43 * @param fd
     44 * @return
     45 */
     46int posix_isatty(int fd)
     47{
    3248        // TODO
    33         return 0;
     49        not_implemented();
    3450}
    3551
     52/** @}
     53 */
  • uspace/lib/posix/unistd.h

    rab547063 r4f4b4e7  
    11/*
    22 * Copyright (c) 2011 Jiri Zarevucky
     3 * Copyright (c) 2011 Petr Koupy
    34 * All rights reserved.
    45 *
     
    2627 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2728 */
    28  
     29
     30/** @addtogroup libposix
     31 * @{
     32 */
     33/** @file
     34 */
     35
    2936#ifndef POSIX_UNISTD_H_
    3037#define POSIX_UNISTD_H_
     
    3239#include "libc/unistd.h"
    3340
    34 /* #include <getopt.h> */
     41/* Process Termination */
     42#define _exit exit
    3543
     44/* Option Arguments */
    3645extern char *optarg;
    3746extern int optind, opterr, optopt;
    3847extern int getopt(int, char * const [], const char *);
    3948
    40 extern int isatty(int fd);
     49/* Identifying Terminals */
     50extern int posix_isatty(int fd);
    4151
     52/* Process Identification */
    4253#define getpid task_get_id
    4354
     55/* Standard Streams */
     56#undef STDIN_FILENO
    4457#define STDIN_FILENO (fileno(stdin))
     58#undef STDOUT_FILENO
    4559#define STDOUT_FILENO (fileno(stdout))
     60#undef STDERR_FILENO
    4661#define STDERR_FILENO (fileno(stderr))
     62
     63#ifndef POSIX_INTERNAL
     64        #define isatty posix_isatty
     65#endif
    4766
    4867#endif /* POSIX_UNISTD_H_ */
    4968
     69/** @}
     70 */
Note: See TracChangeset for help on using the changeset viewer.