Changeset bc56f30 in mainline for uspace/lib/posix/include


Ignore:
Timestamp:
2019-05-27T12:38:26Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0d14c25
Parents:
4d51c60
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-13 16:06:49)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-05-27 12:38:26)
Message:

Make some libc and libposix headers usable in C++

These headers either get included from standard C++ headers,
or are standard themselves, which means any unnamespaced nonstandard
identifiers are a problem. This commit attempts to fix those
issues, and removes hacks previously used in libcpp to work around it.

Location:
uspace/lib/posix/include/posix
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/include/posix/ctype.h

    r4d51c60 rbc56f30  
    3939#include <libc/ctype.h>
    4040
     41__C_DECLS_BEGIN;
     42
    4143/* Obsolete Functions and Macros */
    4244extern int isascii(int c);
     
    4648#define _toupper(c) ((c) - 'a' + 'A')
    4749
     50__C_DECLS_END;
     51
    4852#endif /* POSIX_CTYPE_H_ */
    4953
  • uspace/lib/posix/include/posix/dlfcn.h

    r4d51c60 rbc56f30  
    4141#define RTLD_LOCAL 0
    4242
     43__C_DECLS_BEGIN;
     44
    4345extern void *dlopen(const char *, int);
    4446extern void *dlsym(void *, const char *);
    4547extern int dlclose(void *);
    4648extern char *dlerror(void);
     49
     50__C_DECLS_END;
    4751
    4852#endif
  • uspace/lib/posix/include/posix/fcntl.h

    r4d51c60 rbc56f30  
    3838#include <sys/types.h>
    3939
    40 #undef O_CREAT
    41 #undef O_EXCL
    42 #undef O_TRUNC
    43 #undef O_APPEND
    44 #undef O_RDONLY
    45 #undef O_RDWR
    46 #undef O_WRONLY
    4740#define O_CREAT   1
    4841#define O_EXCL    2
     
    5447
    5548/* Mask for file access modes. */
    56 #undef O_ACCMODE
    5749#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
    5850
    5951/* Dummy compatibility flag */
    60 #undef O_NOCTTY
    6152#define O_NOCTTY 0
    6253
    6354/* fcntl commands */
    64 #undef F_DUPFD
    65 #undef F_DUPFD_CLOEXEC
    66 #undef F_GETFD
    67 #undef F_SETFD
    68 #undef F_GETFL
    69 #undef F_SETFL
    70 #undef F_GETOWN
    71 #undef F_SETOWN
    72 #undef F_GETLK
    73 #undef F_SETLK
    74 #undef F_SETLKW
    7555#define F_DUPFD            0 /* Duplicate file descriptor. */
    7656#define F_DUPFD_CLOEXEC    1 /* Same as F_DUPFD but with FD_CLOEXEC flag set. */
     
    8666
    8767/* File descriptor flags used with F_GETFD and F_SETFD. */
    88 #undef FD_CLOEXEC
    8968#define FD_CLOEXEC         1 /* Close on exec. */
     69
     70__C_DECLS_BEGIN;
    9071
    9172extern int open(const char *pathname, int flags, ...);
    9273extern int fcntl(int fd, int cmd, ...);
     74
     75__C_DECLS_END;
    9376
    9477#endif /* POSIX_FCNTL_H_ */
  • uspace/lib/posix/include/posix/fnmatch.h

    r4d51c60 rbc56f30  
    3636#define POSIX_FNMATCH_H_
    3737
     38#include <_bits/decls.h>
     39
    3840/* Error Values */
    39 #undef FNM_NOMATCH
    4041#define FNM_NOMATCH 1
    4142
    4243/* Flags */
    43 #undef FNM_PATHNAME
    44 #undef FNM_PERIOD
    45 #undef FNM_NOESCAPE
    4644#define FNM_PATHNAME 1
    4745#define FNM_PERIOD 2
     
    4947
    5048/* GNU Extensions */
    51 #undef FNM_FILE_NAME
    52 #undef FNM_LEADING_DIR
    53 #undef FNM_CASEFOLD
    5449#define FNM_FILE_NAME FNM_PATHNAME
    5550#define FNM_LEADING_DIR 8
    5651#define FNM_CASEFOLD 16
    5752
     53__C_DECLS_BEGIN;
     54
    5855extern int fnmatch(const char *pattern, const char *string, int flags);
     56
     57__C_DECLS_END;
    5958
    6059#endif /* POSIX_FNMATCH_H_ */
  • uspace/lib/posix/include/posix/locale.h

    r4d51c60 rbc56f30  
    3737
    3838#include <stddef.h>
     39#include <_bits/decls.h>
    3940
    40 #ifndef __locale_t_defined
    41 #define __locale_t_defined
    42 typedef struct __posix_locale *locale_t;
    43 #endif
    44 
    45 #undef LC_ALL
    46 #undef LC_COLLATE
    47 #undef LC_CTYPE
    48 #undef LC_MESSAGES
    49 #undef LC_MONETARY
    50 #undef LC_NUMERIC
    51 #undef LC_TIME
    5241#define LC_ALL 0
    5342#define LC_COLLATE 1
     
    5847#define LC_TIME 6
    5948
    60 #undef LC_COLLATE_MASK
    61 #undef LC_CTYPE_MASK
    62 #undef LC_MESSAGES_MASK
    63 #undef LC_MONETARY_MASK
    64 #undef LC_NUMERIC_MASK
    65 #undef LC_TIME_MASK
    66 #undef LC_ALL_MASK
    6749#define LC_COLLATE_MASK (1 << 0)
    6850#define LC_CTYPE_MASK (1 << 1)
     
    7456    LC_MONETARY_MASK | LC_NUMERIC_MASK | LC_TIME_MASK)
    7557
    76 #undef LC_GLOBAL_LOCALE
    7758#define LC_GLOBAL_LOCALE NULL
     59
     60__C_DECLS_BEGIN;
     61
     62#ifndef __locale_t_defined
     63#define __locale_t_defined
     64typedef struct __posix_locale *locale_t;
     65#endif
    7866
    7967struct lconv {
     
    114102extern locale_t uselocale(locale_t newloc);
    115103
     104__C_DECLS_END;
     105
    116106#endif /* POSIX_LOCALE_H_ */
    117107
  • uspace/lib/posix/include/posix/pthread.h

    r4d51c60 rbc56f30  
    3434
    3535#include <time.h>
     36#include <_bits/decls.h>
     37
     38#define PTHREAD_MUTEX_RECURSIVE 1
     39
     40#define PTHREAD_MUTEX_INITIALIZER { 0 }
     41
     42#define PTHREAD_COND_INITIALIZER { 0 }
     43
     44__C_DECLS_BEGIN;
    3645
    3746typedef void *pthread_t;
     
    4352typedef int pthread_key_t;
    4453
    45 #define PTHREAD_MUTEX_RECURSIVE 1
    46 
    4754typedef struct pthread_mutex {
    4855        int dummy;
    4956} pthread_mutex_t;
    50 
    51 #define PTHREAD_MUTEX_INITIALIZER { 0 }
    5257
    5358typedef struct {
     
    6267        int dummy;
    6368} pthread_cond_t;
    64 
    65 #define PTHREAD_COND_INITIALIZER { 0 }
    6669
    6770extern pthread_t pthread_self(void);
     
    106109extern int pthread_key_create(pthread_key_t *, void (*)(void *));
    107110
     111__C_DECLS_END;
     112
    108113#endif
    109114
  • uspace/lib/posix/include/posix/pwd.h

    r4d51c60 rbc56f30  
    3737
    3838#include <sys/types.h>
     39#include <_bits/decls.h>
     40
     41__C_DECLS_BEGIN;
    3942
    4043struct passwd {
     
    5861    char *buffer, size_t bufsize, struct passwd **result);
    5962
     63__C_DECLS_END;
     64
    6065#endif /* POSIX_PWD_H_ */
    6166
  • uspace/lib/posix/include/posix/signal.h

    r4d51c60 rbc56f30  
    3939#include <ucontext.h>
    4040
    41 extern void __posix_default_signal_handler(int signo);
    42 extern void __posix_hold_signal_handler(int signo);
    43 extern void __posix_ignore_signal_handler(int signo);
    44 
    45 #undef SIG_DFL
    4641#define SIG_DFL ((void (*)(int)) __posix_default_signal_handler)
    47 #undef SIG_ERR
    4842#define SIG_ERR ((void (*)(int)) NULL)
    49 #undef SIG_HOLD
    5043#define SIG_HOLD ((void (*)(int)) __posix_hold_signal_handler)
    51 #undef SIG_IGN
    5244#define SIG_IGN ((void (*)(int)) __posix_ignore_signal_handler)
    5345
    54 typedef struct {
    55         int si_signo;
    56         int si_code;
    57 
    58         int si_errno;
    59 
    60         pid_t si_pid;
    61         uid_t si_uid;
    62         void *si_addr;
    63         int si_status;
    64 
    65         long si_band;
    66 
    67         union sigval si_value;
    68 } siginfo_t;
    69 
    70 struct sigaction {
    71         void (*sa_handler)(int);
    72         sigset_t sa_mask;
    73         int sa_flags;
    74         void (*sa_sigaction)(int, siginfo_t *, void *);
    75 };
    76 
    7746/* Values of sigevent::sigev_notify */
    78 #undef SIGEV_NONE
    79 #undef SIGEV_SIGNAL
    80 #undef SIGEV_THREAD
    8147#define SIGEV_NONE 0
    8248#define SIGEV_SIGNAL 0
    8349#define SIGEV_THREAD 0
    8450
    85 #undef SIGRT_MIN
    86 #undef SIGRT_MAX
    8751#define SIGRT_MIN 0
    8852#define SIGRT_MAX 0
    8953
    90 #undef SIG_BLOCK
    91 #undef SIG_UNBLOCK
    92 #undef SIG_SETMASK
    9354#define SIG_BLOCK 0
    9455#define SIG_UNBLOCK 1
    9556#define SIG_SETMASK 2
    9657
    97 #undef SA_NOCLDSTOP
    98 #undef SA_ONSTACK
    99 #undef SA_RESETHAND
    100 #undef SA_RESTART
    101 #undef SA_SIGINFO
    102 #undef SA_NOCLDWAIT
    103 #undef SA_NODEFER
    10458#define SA_NOCLDSTOP (1 << 0)
    10559#define SA_ONSTACK (1 << 1)
     
    11064#define SA_NODEFER (1 << 6)
    11165
    112 #undef SS_ONSTACK
    113 #undef SS_DISABLE
    11466#define SS_ONSTACK 0
    11567#define SS_DISABLE 0
    11668
    117 #undef MINSIGSTKSZ
    118 #undef SIGSTKSZ
    11969#define MINSIGSTKSZ 0
    12070#define SIGSTKSZ 0
     71
     72__C_DECLS_BEGIN;
     73
     74extern void __posix_default_signal_handler(int signo);
     75extern void __posix_hold_signal_handler(int signo);
     76extern void __posix_ignore_signal_handler(int signo);
     77
     78typedef struct {
     79        int si_signo;
     80        int si_code;
     81
     82        int si_errno;
     83
     84        pid_t si_pid;
     85        uid_t si_uid;
     86        void *si_addr;
     87        int si_status;
     88
     89        long si_band;
     90
     91        union sigval si_value;
     92} siginfo_t;
     93
     94struct sigaction {
     95        void (*sa_handler)(int);
     96        sigset_t sa_mask;
     97        int sa_flags;
     98        void (*sa_sigaction)(int, siginfo_t *, void *);
     99};
    121100
    122101/* Full POSIX set */
     
    245224    sigset_t *__restrict__ oset);
    246225
     226__C_DECLS_END;
     227
    247228#endif /* POSIX_SIGNAL_H_ */
    248229
  • uspace/lib/posix/include/posix/stdio.h

    r4d51c60 rbc56f30  
    4545#include <limits.h>
    4646
     47#define P_tmpdir "/tmp"
     48
     49#define L_ctermid PATH_MAX
     50
     51__C_DECLS_BEGIN;
     52
    4753extern FILE *fdopen(int, const char *);
    4854extern int fileno(FILE *);
    4955
    50 #define P_tmpdir "/tmp"
    51 
    5256/* Identifying the Terminal */
    53 #undef L_ctermid
    54 #define L_ctermid PATH_MAX
    5557extern char *ctermid(char *s);
    5658
     
    98100extern char *tempnam(const char *dir, const char *pfx);
    99101
     102__C_DECLS_END;
     103
    100104#endif /* POSIX_STDIO_H_ */
    101105
  • uspace/lib/posix/include/posix/stdlib.h

    r4d51c60 rbc56f30  
    4242#include <stddef.h>
    4343
     44__C_DECLS_BEGIN;
     45
    4446/* Environment Access */
    4547extern int putenv(char *string);
     
    6062extern int bsd_getloadavg(double loadavg[], int nelem);
    6163
     64__C_DECLS_END;
     65
    6266#endif  // POSIX_STDLIB_H_
    6367
  • uspace/lib/posix/include/posix/string.h

    r4d51c60 rbc56f30  
    4747
    4848#include <libc/mem.h>
    49 #ifdef _HELENOS_SOURCE
    50 #undef _HELENOS_SOURCE
     49
     50#define _REALLY_WANT_STRING_H
    5151#include <libc/string.h>
    52 #define _HELENOS_SOURCE
    53 #else
    54 #include <libc/string.h>
    55 #endif
     52
     53__C_DECLS_BEGIN;
    5654
    5755/* Copying and Concatenation */
     
    7371
    7472/* Legacy Declarations */
    75 #ifndef POSIX_STRINGS_H_
    7673extern int ffs(int i);
    7774extern int strcasecmp(const char *s1, const char *s2);
    7875extern int strncasecmp(const char *s1, const char *s2, size_t n);
    79 #endif
     76
     77__C_DECLS_END;
    8078
    8179#endif  // POSIX_STRING_H_
  • uspace/lib/posix/include/posix/strings.h

    r4d51c60 rbc56f30  
    3939#include <types/common.h>
    4040
     41__C_DECLS_BEGIN;
     42
    4143/* Search Functions */
    42 #ifndef POSIX_STRING_H_
    4344extern int ffs(int i);
    44 #endif
    4545
    4646/* String/Array Comparison */
    47 #ifndef POSIX_STRING_H_
    4847extern int strcasecmp(const char *s1, const char *s2);
    4948extern int strncasecmp(const char *s1, const char *s2, size_t n);
    50 #endif
    5149
    5250/*
     
    6462extern char *rindex(const char *s, int c);
    6563
     64__C_DECLS_END;
     65
    6666#endif  // POSIX_STRINGS_H_
    6767
  • uspace/lib/posix/include/posix/sys/mman.h

    r4d51c60 rbc56f30  
    3737
    3838#include <sys/types.h>
    39 #include <abi/mm/as.h>
     39#include <_bits/decls.h>
    4040
    41 #define MAP_FAILED ((void *) -1)
     41#define MAP_FAILED  ((void *) -1)
    4242
    4343#define MAP_SHARED     (1 << 0)
     
    4545#define MAP_FIXED      (1 << 2)
    4646#define MAP_ANONYMOUS  (1 << 3)
    47 #define MAP_ANON MAP_ANONYMOUS
     47#define MAP_ANON       MAP_ANONYMOUS
    4848
    49 #undef PROT_NONE
    50 #undef PROT_READ
    51 #undef PROT_WRITE
    52 #undef PROT_EXEC
    53 #define PROT_NONE  0
    54 #define PROT_READ  AS_AREA_READ
    55 #define PROT_WRITE AS_AREA_WRITE
    56 #define PROT_EXEC  AS_AREA_EXEC
     49#define PROT_NONE   0
     50#define PROT_READ   1
     51#define PROT_WRITE  2
     52#define PROT_EXEC   4
     53
     54__C_DECLS_BEGIN;
    5755
    5856extern void *mmap(void *start, size_t length, int prot, int flags, int fd,
     
    6058extern int munmap(void *start, size_t length);
    6159
     60__C_DECLS_END;
     61
    6262#endif /* POSIX_SYS_MMAN_H_ */
    6363
  • uspace/lib/posix/include/posix/sys/stat.h

    r4d51c60 rbc56f30  
    3939#include <sys/types.h>
    4040#include <time.h>
     41#include <_bits/decls.h>
    4142
    4243/* values are the same as on Linux */
    4344
    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
    5245#define S_IFMT     0170000   /* all file types */
    5346#define S_IFSOCK   0140000   /* socket */
     
    5952#define S_IFIFO    0010000   /* FIFO */
    6053
    61 #undef S_ISUID
    62 #undef S_ISGID
    63 #undef S_ISVTX
    6454#define S_ISUID    0004000   /* SUID */
    6555#define S_ISGID    0002000   /* SGID */
    6656#define S_ISVTX    0001000   /* sticky */
    6757
    68 #undef S_IRWXU
    69 #undef S_IRUSR
    70 #undef S_IWUSR
    71 #undef S_IXUSR
    7258#define S_IRWXU    00700     /* owner permissions */
    7359#define S_IRUSR    00400
     
    7561#define S_IXUSR    00100
    7662
    77 #undef S_IRWXG
    78 #undef S_IRGRP
    79 #undef S_IWGRP
    80 #undef S_IXGRP
    8163#define S_IRWXG    00070     /* group permissions */
    8264#define S_IRGRP    00040
     
    8466#define S_IXGRP    00010
    8567
    86 #undef S_IRWXO
    87 #undef S_IROTH
    88 #undef S_IWOTH
    89 #undef S_IXOTH
    9068#define S_IRWXO    00007     /* other permissions */
    9169#define S_IROTH    00004
     
    9371#define S_IXOTH    00001
    9472
    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
    10273#define S_ISREG(m) ((m & S_IFREG) != 0)
    10374#define S_ISDIR(m) ((m & S_IFDIR) != 0)
     
    10778#define S_ISLNK(m) ((m & S_IFLNK) != 0) /* symbolic link? (Not in POSIX.1-1996.) */
    10879#define S_ISSOCK(m) ((m & S_IFSOCK) != 0) /* socket? (Not in POSIX.1-1996.) */
     80
     81__C_DECLS_BEGIN;
    10982
    11083struct stat {
     
    131104extern int mkdir(const char *path, mode_t mode);
    132105
     106__C_DECLS_END;
     107
    133108#endif /* POSIX_SYS_STAT_H */
    134109
  • uspace/lib/posix/include/posix/sys/time.h

    r4d51c60 rbc56f30  
    3535
    3636#include <time.h>
     37#include <_bits/decls.h>
     38
     39__C_DECLS_BEGIN;
    3740
    3841struct timeval {
     
    4346extern int gettimeofday(struct timeval *, void *);
    4447
     48__C_DECLS_END;
     49
    4550#endif
    4651
  • uspace/lib/posix/include/posix/sys/types.h

    r4d51c60 rbc56f30  
    3737#define POSIX_SYS_TYPES_H_
    3838
    39 #include <types/common.h>
     39#include <stddef.h>
     40#include <stdint.h>
     41#include <_bits/ssize_t.h>
     42#include <_bits/decls.h>
     43
     44__C_DECLS_BEGIN;
    4045
    4146typedef unsigned int ino_t;
     
    4651typedef long blkcnt_t;
    4752typedef int pid_t;
    48 typedef sysarg_t dev_t;
     53typedef unsigned long dev_t;
    4954typedef unsigned int mode_t;
    5055
     
    6772typedef long suseconds_t;
    6873
     74__C_DECLS_END;
     75
    6976#endif /* POSIX_SYS_TYPES_H_ */
    7077
  • uspace/lib/posix/include/posix/sys/wait.h

    r4d51c60 rbc56f30  
    3737
    3838#include <sys/types.h>
     39#include <_bits/decls.h>
    3940
    40 #undef WIFEXITED
    41 #undef WEXITSTATUS
    42 #undef WIFSIGNALED
    43 #undef WTERMSIG
    4441#define WIFEXITED(status) __posix_wifexited(status)
    4542#define WEXITSTATUS(status) __posix_wexitstatus(status)
    4643#define WIFSIGNALED(status) __posix_wifsignaled(status)
    4744#define WTERMSIG(status) __posix_wtermsig(status)
     45
     46__C_DECLS_BEGIN;
    4847
    4948extern int __posix_wifexited(int status);
     
    5554extern pid_t waitpid(pid_t pid, int *stat_ptr, int options);
    5655
     56__C_DECLS_END;
     57
    5758#endif /* POSIX_SYS_WAIT_H_ */
    5859
  • uspace/lib/posix/include/posix/time.h

    r4d51c60 rbc56f30  
    4141#include <libc/time.h>
    4242
     43#define CLOCK_REALTIME ((clockid_t) 0)
     44
     45#define ASCTIME_BUF_LEN  26
     46
     47__C_DECLS_BEGIN;
     48
    4349#ifndef __locale_t_defined
    4450#define __locale_t_defined
     
    4652#endif
    4753
    48 #ifndef POSIX_SIGNAL_H_
    4954struct sigevent;
    50 #endif
    51 
    52 #undef CLOCK_REALTIME
    53 #define CLOCK_REALTIME ((clockid_t) 0)
    54 
    55 #define ASCTIME_BUF_LEN  26
    5655
    5756struct itimerspec {
     
    9796    const struct timespec *rqtp, struct timespec *rmtp);
    9897
     98__C_DECLS_END;
     99
    99100#endif  // POSIX_TIME_H_
    100101
  • uspace/lib/posix/include/posix/ucontext.h

    r4d51c60 rbc56f30  
    3737
    3838#include <sys/types.h>
     39#include <_bits/decls.h>
     40
     41__C_DECLS_BEGIN;
    3942
    4043typedef int sig_atomic_t;
     
    7174} ucontext_t;
    7275
     76__C_DECLS_END;
     77
    7378#endif
    7479
  • uspace/lib/posix/include/posix/unistd.h

    r4d51c60 rbc56f30  
    4646/* Process Termination */
    4747#define _exit exit
     48
     49/* Standard Streams */
     50#define STDIN_FILENO (fileno(stdin))
     51#define STDOUT_FILENO (fileno(stdout))
     52#define STDERR_FILENO (fileno(stderr))
     53
     54#define F_OK 0 /* Test for existence. */
     55#define X_OK 1 /* Test for execute permission. */
     56#define W_OK 2 /* Test for write permission. */
     57#define R_OK 4 /* Test for read permission. */
     58
     59__C_DECLS_BEGIN;
    4860
    4961extern char *optarg;
     
    106118#endif
    107119
    108 /* Standard Streams */
    109 #undef STDIN_FILENO
    110 #define STDIN_FILENO (fileno(stdin))
    111 #undef STDOUT_FILENO
    112 #define STDOUT_FILENO (fileno(stdout))
    113 #undef STDERR_FILENO
    114 #define STDERR_FILENO (fileno(stderr))
    115 
    116120/* File Accessibility */
    117 #undef F_OK
    118 #undef X_OK
    119 #undef W_OK
    120 #undef R_OK
    121 #define F_OK 0 /* Test for existence. */
    122 #define X_OK 1 /* Test for execute permission. */
    123 #define W_OK 2 /* Test for write permission. */
    124 #define R_OK 4 /* Test for read permission. */
    125121extern int access(const char *path, int amode);
    126122
     
    171167extern unsigned int alarm(unsigned int);
    172168
     169__C_DECLS_END;
     170
    173171#endif /* POSIX_UNISTD_H_ */
    174172
Note: See TracChangeset for help on using the changeset viewer.