Changeset bc56f30 in mainline for uspace/lib/c/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/c/include
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/adt/list.h

    r4d51c60 rbc56f30  
    4242#include <stdint.h>
    4343#include <trace.h>
    44 
    45 /** Doubly linked list link. */
    46 typedef struct link {
    47         struct link *prev;  /**< Pointer to the previous item in the list. */
    48         struct link *next;  /**< Pointer to the next item in the list. */
    49 } link_t;
    50 
    51 /** Doubly linked list. */
    52 typedef struct list {
    53         link_t head;  /**< List head. Does not have any data. */
    54 } list_t;
    55 
    56 extern bool list_member(const link_t *, const list_t *);
    57 extern void list_splice(list_t *, link_t *);
    58 extern unsigned long list_count(const list_t *);
     44#include <_bits/decls.h>
     45
     46#ifndef __cplusplus
     47
     48/**
     49 * We don't define the macros in C++ to avoid polluting headers with
     50 * namespaceless names. We don't actually need them, so this is fine.
     51 * We still allow including the rest of the file (in `helenos` namespace)
     52 * so that we can expose publicly visible types that have list_t members.
     53 */
    5954
    6055/** Declare and initialize statically allocated list.
     
    138133        assert(!link_used(link))
    139134
     135#define list_pop(list, type, member) \
     136        ((type *) list_pop_internal(list, \
     137            (list_link_to_void(&(((type *) NULL)->member)) - NULL)))
     138
     139#endif  /* !__cplusplus */
     140
     141__HELENOS_DECLS_BEGIN;
     142
     143/** Doubly linked list link. */
     144typedef struct __adt_list_link {
     145        struct __adt_list_link *prev;  /**< Pointer to the previous item in the list. */
     146        struct __adt_list_link *next;  /**< Pointer to the next item in the list. */
     147} link_t;
     148
     149/** Doubly linked list. */
     150typedef struct {
     151        link_t head;  /**< List head. Does not have any data. */
     152} list_t;
     153
     154extern bool list_member(const link_t *, const list_t *);
     155extern void list_splice(list_t *, link_t *);
     156extern unsigned long list_count(const list_t *);
     157
    140158/** Returns true if the link is definitely part of a list. False if not sure. */
    141159static inline bool link_in_use(const link_t *link)
     
    425443}
    426444
    427 #define list_pop(list, type, member) \
    428         ((type *) list_pop_internal(list, \
    429             (list_link_to_void(&(((type *) NULL)->member)) - NULL)))
     445__HELENOS_DECLS_END;
    430446
    431447#endif
  • uspace/lib/c/include/assert.h

    r4d51c60 rbc56f30  
    4141#define _LIBC_ASSERT_H_
    4242
     43#include <_bits/decls.h>
     44
    4345#ifndef __cplusplus
    4446#define static_assert _Static_assert
    4547#endif
     48
     49__C_DECLS_BEGIN;
    4650
    4751extern void __helenos_assert_abort(const char *, const char *, unsigned int)
     
    5054extern void __helenos_assert_quick_abort(const char *, const char *, unsigned int)
    5155    __attribute__((noreturn));
     56
     57__C_DECLS_END;
    5258
    5359#endif
  • uspace/lib/c/include/bsearch.h

    r4d51c60 rbc56f30  
    3737
    3838#include <stddef.h>
     39#include <_bits/decls.h>
     40
     41__C_DECLS_BEGIN;
    3942
    4043extern void *bsearch(const void *, const void *, size_t, size_t,
    4144    int (*)(const void *, const void *));
     45
     46__C_DECLS_END;
    4247
    4348#endif
  • uspace/lib/c/include/ctype.h

    r4d51c60 rbc56f30  
    3030#define _LIBC_CTYPE_H_
    3131
     32#include <_bits/decls.h>
     33
     34__C_DECLS_BEGIN;
    3235int islower(int);
    3336int isupper(int);
     
    4447int tolower(int);
    4548int toupper(int);
     49__C_DECLS_END;
    4650
    4751#endif
  • uspace/lib/c/include/dirent.h

    r4d51c60 rbc56f30  
    3636#define _LIBC_DIRENT_H_
    3737
    38 #define NAME_MAX  256
     38#include <limits.h>
     39#include <_bits/decls.h>
     40
     41__C_DECLS_BEGIN;
    3942
    4043struct dirent {
    41         char d_name[NAME_MAX + 1];
     44        char d_name[__NAME_MAX + 1];
    4245};
    4346
     
    4952extern int closedir(DIR *);
    5053
     54__C_DECLS_END;
     55
    5156#endif
    5257
  • uspace/lib/c/include/dlfcn.h

    r4d51c60 rbc56f30  
    3737#define _LIBC_DLFCN_H_
    3838
     39#include <_bits/decls.h>
     40
     41__C_DECLS_BEGIN;
     42
    3943void *dlopen(const char *, int);
    4044void *dlsym(void *, const char *);
     45
     46__C_DECLS_END;
    4147
    4248#endif
  • uspace/lib/c/include/errno.h

    r4d51c60 rbc56f30  
    3838#include <_bits/errno.h>
    3939#include <abi/errno.h>
     40#include <_bits/decls.h>
    4041
    41 #define errno  (*(__errno()))
     42__HELENOS_DECLS_BEGIN;
    4243
    4344extern errno_t *__errno(void) __attribute__((const));
     45
     46__HELENOS_DECLS_END;
     47
     48#ifdef __cplusplus
     49#define errno  (*(::helenos::__errno()))
     50#else
     51#define errno  (*(__errno()))
     52#endif
    4453
    4554#endif
  • uspace/lib/c/include/fibril.h

    r4d51c60 rbc56f30  
    3636#define _LIBC_FIBRIL_H_
    3737
    38 #include <types/common.h>
    3938#include <time.h>
     39#include <_bits/errno.h>
    4040#include <_bits/__noreturn.h>
     41#include <_bits/decls.h>
     42
     43__HELENOS_DECLS_BEGIN;
    4144
    4245typedef struct fibril fibril_t;
     
    7174extern __noreturn void fibril_exit(long);
    7275
     76__HELENOS_DECLS_END;
     77
    7378#endif
    7479
  • uspace/lib/c/include/fibril_synch.h

    r4d51c60 rbc56f30  
    4040#include <time.h>
    4141#include <stdbool.h>
    42 
    43 typedef struct {
    44         fibril_owner_info_t oi;  /**< Keep this the first thing. */
    45         int counter;
    46         list_t waiters;
    47 } fibril_mutex_t;
     42#include <_bits/decls.h>
     43
     44#ifndef __cplusplus
    4845
    4946#define FIBRIL_MUTEX_INITIALIZER(name) \
     
    5855#define FIBRIL_MUTEX_INITIALIZE(name) \
    5956        fibril_mutex_t name = FIBRIL_MUTEX_INITIALIZER(name)
    60 
    61 typedef struct {
    62         fibril_owner_info_t oi;  /**< Keep this the first thing. */
    63         unsigned int writers;
    64         unsigned int readers;
    65         list_t waiters;
    66 } fibril_rwlock_t;
    6757
    6858#define FIBRIL_RWLOCK_INITIALIZER(name) \
     
    7969        fibril_rwlock_t name = FIBRIL_RWLOCK_INITIALIZER(name)
    8070
    81 typedef struct {
    82         list_t waiters;
    83 } fibril_condvar_t;
    84 
    8571#define FIBRIL_CONDVAR_INITIALIZER(name) \
    8672        { \
     
    9076#define FIBRIL_CONDVAR_INITIALIZE(name) \
    9177        fibril_condvar_t name = FIBRIL_CONDVAR_INITIALIZER(name)
     78
     79#define FIBRIL_SEMAPHORE_INITIALIZER(name, cnt) \
     80        { \
     81                .count = (cnt), \
     82                .waiters = LIST_INITIALIZER((name).waiters), \
     83        }
     84
     85#define FIBRIL_SEMAPHORE_INITIALIZE(name, cnt) \
     86        fibril_semaphore_t name = FIBRIL_SEMAPHORE_INITIALIZER(name, cnt)
     87
     88#endif
     89
     90__HELENOS_DECLS_BEGIN;
     91
     92typedef struct {
     93        fibril_owner_info_t oi;  /**< Keep this the first thing. */
     94        int counter;
     95        list_t waiters;
     96} fibril_mutex_t;
     97
     98typedef struct {
     99        fibril_owner_info_t oi;  /**< Keep this the first thing. */
     100        unsigned int writers;
     101        unsigned int readers;
     102        list_t waiters;
     103} fibril_rwlock_t;
     104
     105typedef struct {
     106        list_t waiters;
     107} fibril_condvar_t;
    92108
    93109typedef void (*fibril_timer_fun_t)(void *);
     
    134150} fibril_semaphore_t;
    135151
    136 #define FIBRIL_SEMAPHORE_INITIALIZER(name, cnt) \
    137         { \
    138                 .count = (cnt), \
    139                 .waiters = LIST_INITIALIZER((name).waiters), \
    140         }
    141 
    142 #define FIBRIL_SEMAPHORE_INITIALIZE(name, cnt) \
    143         fibril_semaphore_t name = FIBRIL_SEMAPHORE_INITIALIZER(name, cnt)
    144 
    145152extern void __fibril_synch_init(void);
    146153extern void __fibril_synch_fini(void);
     
    190197extern void mpsc_close(mpsc_t *);
    191198
     199__HELENOS_DECLS_END;
     200
    192201#endif
    193202
  • uspace/lib/c/include/malloc.h

    r4d51c60 rbc56f30  
    3737
    3838#include <stddef.h>
     39#include <_bits/decls.h>
     40
     41__C_DECLS_BEGIN;
    3942
    4043extern void *malloc(size_t size)
     
    4245extern void *calloc(size_t nmemb, size_t size)
    4346    __attribute__((malloc));
    44 extern void *memalign(size_t align, size_t size)
    45     __attribute__((malloc));
    4647extern void *realloc(void *addr, size_t size)
    4748    __attribute__((warn_unused_result));
    4849extern void free(void *addr);
     50
     51__C_DECLS_END;
     52
     53#ifdef _HELENOS_SOURCE
     54__HELENOS_DECLS_BEGIN;
     55
     56extern void *memalign(size_t align, size_t size)
     57    __attribute__((malloc));
    4958extern void *heap_check(void);
     59
     60__HELENOS_DECLS_END;
     61#endif
    5062
    5163#endif
  • uspace/lib/c/include/mem.h

    r4d51c60 rbc56f30  
    3838
    3939#include <stddef.h>
     40#include <_bits/decls.h>
     41
     42__C_DECLS_BEGIN;
    4043
    4144extern void *memset(void *, int, size_t)
     
    5053    __attribute__((nonnull(1)));
    5154
     55__C_DECLS_END;
     56
    5257#endif
    5358
  • uspace/lib/c/include/offset.h

    r4d51c60 rbc56f30  
    3636#define _LIBC_OFFSET_H_
    3737
     38#ifndef _HELENOS_SOURCE
     39#error This file should only be included from HelenOS sources
     40#endif
     41
    3842#include <stdint.h>
     43#include <_bits/decls.h>
     44#include <_bits/off64_t.h>
    3945
    4046/* off64_t */
     
    5258#define PRIXOFF64 PRIX64
    5359
    54 /** Relative offset */
    55 typedef int64_t off64_t;
     60__HELENOS_DECLS_BEGIN;
    5661
    5762/** Absolute offset */
    5863typedef uint64_t aoff64_t;
     64
     65__HELENOS_DECLS_END;
    5966
    6067#endif
  • uspace/lib/c/include/qsort.h

    r4d51c60 rbc56f30  
    3737
    3838#include <stddef.h>
     39#include <_bits/decls.h>
    3940
     41__C_DECLS_BEGIN;
    4042extern void qsort(void *, size_t, size_t, int (*)(const void *,
    4143    const void *));
     44__C_DECLS_END;
     45
     46#ifdef _HELENOS_SOURCE
     47__HELENOS_DECLS_BEGIN;
    4248extern void qsort_r(void *, size_t, size_t, int (*)(const void *,
    4349    const void *, void *), void *);
     50__HELENOS_DECLS_END;
     51#endif
    4452
    4553#endif
  • uspace/lib/c/include/setjmp.h

    r4d51c60 rbc56f30  
    3434#define _LIBC_SETJMP_H_
    3535
    36 #ifdef __cplusplus
    37 extern "C" {
    38 #endif
    39 
    4036#include <libarch/fibril_context.h>
    4137#include <_bits/__noreturn.h>
     38#include <_bits/decls.h>
     39
     40__C_DECLS_BEGIN;
    4241
    4342typedef __context_t jmp_buf[1];
     
    4645extern __noreturn void __context_restore(__context_t *, int);
    4746
    48 #define setjmp __context_save
    4947extern __noreturn void longjmp(jmp_buf, int);
    5048
    51 #ifdef __cplusplus
    52 }
    53 #endif
     49__C_DECLS_END;
     50
     51#define setjmp __context_save
    5452
    5553#endif
  • uspace/lib/c/include/stdio.h

    r4d51c60 rbc56f30  
    3737#define _LIBC_STDIO_H_
    3838
    39 #ifdef __cplusplus
    40 extern "C" {
    41 #endif
    42 
    43 #include <offset.h>
    4439#include <stdarg.h>
    4540#include <io/verify.h>
     
    4843#include <_bits/wchar_t.h>
    4944#include <_bits/wint_t.h>
    50 
    51 /** Forward declaration */
    52 struct _IO_FILE;
    53 typedef struct _IO_FILE FILE;
    54 
    55 /** File position */
    56 typedef struct {
    57         off64_t pos;
    58 } fpos_t;
     45#include <_bits/decls.h>
    5946
    6047#ifndef _HELENOS_SOURCE
     
    7057
    7158/** Max number of files that is guaranteed to be able to open at the same time */
    72 #define FOPEN_MAX VFS_MAX_OPEN_FILES
     59#define FOPEN_MAX 16
    7360
    7461/** Recommended size of fixed-size array for holding file names. */
     
    9279/** Minimum number of unique temporary file names */
    9380#define TMP_MAX 1000000
     81
     82__C_DECLS_BEGIN;
     83
     84/** Forward declaration */
     85struct _IO_FILE;
     86typedef struct _IO_FILE FILE;
     87
     88/** File position */
     89typedef struct {
     90        long long pos;
     91} fpos_t;
    9492
    9593extern FILE *stdin;
     
    9896
    9997/* Character and string input functions */
    100 #define getc fgetc
    10198extern int fgetc(FILE *);
    10299extern char *fgets(char *, int, FILE *);
    103100extern char *gets(char *, size_t) __attribute__((deprecated));
    104101
     102static inline int getc(FILE *f)
     103{
     104        return fgetc(f);
     105}
     106
    105107extern int getchar(void);
    106108
    107109/* Character and string output functions */
    108 #define putc fputc
    109110extern int fputc(int, FILE *);
    110111extern int fputs(const char *, FILE *);
     112
     113static inline int putc(int i, FILE *f)
     114{
     115        return fputc(i, f);
     116}
    111117
    112118extern int putchar(int);
     
    180186extern char *tmpnam(char *s);
    181187
     188__C_DECLS_END;
     189
    182190#ifdef _HELENOS_SOURCE
    183191
     192#include <_bits/off64_t.h>
     193
     194__HELENOS_DECLS_BEGIN;
     195
    184196/* Nonstandard extensions. */
    185197
    186 enum _buffer_type {
     198enum __buffer_type {
    187199        /** No buffering */
    188200        _IONBF,
     
    193205};
    194206
    195 enum _buffer_state {
    196         /** Buffer is empty */
    197         _bs_empty,
    198 
    199         /** Buffer contains data to be written */
    200         _bs_write,
    201 
    202         /** Buffer contains prefetched data for reading */
    203         _bs_read
    204 };
    205 
    206207extern int vprintf_length(const char *, va_list);
    207208extern int printf_length(const char *, ...)
     
    210211extern int fileno(FILE *);
    211212
    212 #include <offset.h>
    213 
    214213extern int fseek64(FILE *, off64_t, int);
    215214extern off64_t ftell64(FILE *);
    216215
    217 #endif
    218 
    219 #ifdef __cplusplus
    220 }
     216__HELENOS_DECLS_END;
    221217#endif
    222218
  • uspace/lib/c/include/stdlib.h

    r4d51c60 rbc56f30  
    3636#define _LIBC_STDLIB_H_
    3737
    38 #ifdef __cplusplus
    39 extern "C" {
    40 #endif
    41 
    4238#include <_bits/size_t.h>
    4339#include <_bits/wchar_t.h>
     40#include <_bits/decls.h>
    4441#include <bsearch.h>
    4542#include <malloc.h>
    4643#include <qsort.h>
     44
     45#define EXIT_SUCCESS 0
     46#define EXIT_FAILURE 1
     47
     48#define RAND_MAX  714025
     49
     50#define MB_CUR_MAX 4
     51
     52__C_DECLS_BEGIN;
    4753
    4854/** Type returned by the div function */
     
    6975        long long rem;
    7076} lldiv_t;
    71 
    72 #define EXIT_FAILURE 1
    73 #define EXIT_SUCCESS 0
    74 
    75 #define RAND_MAX  714025
    76 
    77 #define MB_CUR_MAX 4
    7877
    7978extern long double strtold(const char *, char **);
     
    109108extern lldiv_t lldiv(long long, long long);
    110109
    111 #ifdef __cplusplus
    112 }
    113 #endif
     110__C_DECLS_END;
    114111
    115112#endif
  • uspace/lib/c/include/str.h

    r4d51c60 rbc56f30  
    3838#define _LIBC_STR_H_
    3939
    40 #ifdef __cplusplus
    41 extern "C" {
    42 #endif
    43 
    4440#include <errno.h>
    4541#include <stdbool.h>
     
    4844
    4945#include <mem.h>
     46#include <_bits/decls.h>
     47
     48#ifndef __cplusplus
    5049
    5150/* Common Unicode characters */
     
    6362 */
    6463#define SPASCII_STR_BUFSIZE(spa_size) ((spa_size) + 1)
     64
     65#endif
     66
     67__HELENOS_DECLS_BEGIN;
    6568
    6669extern wchar_t str_decode(const char *str, size_t *offset, size_t sz);
     
    147150extern unsigned long strtoul(const char *, char **, int);
    148151
    149 #ifdef __cplusplus
    150 }
    151 #endif
     152__HELENOS_DECLS_END;
    152153
    153154#endif
  • uspace/lib/c/include/string.h

    r4d51c60 rbc56f30  
    4141#endif
    4242
     43#include <_bits/decls.h>
    4344#include <_bits/size_t.h>
    4445#include <_bits/NULL.h>
    4546#include <mem.h>
     47
     48__C_DECLS_BEGIN;
    4649
    4750extern char *strcpy(char *, const char *);
     
    7073#endif
    7174
     75__C_DECLS_END;
     76
    7277#endif
    7378
  • uspace/lib/c/include/time.h

    r4d51c60 rbc56f30  
    3636#define _LIBC_TIME_H_
    3737
    38 #ifdef __cplusplus
    39 extern "C" {
    40 #endif
     38#include <_bits/decls.h>
    4139
    4240/* ISO/IEC 9899:2011 7.27.1 (2) */
     
    5149
    5250#include <_bits/size_t.h>
     51
     52__C_DECLS_BEGIN;
    5353
    5454/* ISO/IEC 9899:2011 7.27.1 (3), (4) */
     
    106106    const struct tm *__restrict__);
    107107
     108__C_DECLS_END;
     109
    108110#ifdef _HELENOS_SOURCE
    109111
     
    114116#include <stdbool.h>
    115117#include <_bits/errno.h>
     118
     119__HELENOS_DECLS_BEGIN;
    116120
    117121typedef long long sec_t;
     
    155159extern void udelay(sysarg_t);
    156160
     161__HELENOS_DECLS_END;
     162
    157163#endif /* _HELENOS_SOURCE */
    158 
    159 #ifdef __cplusplus
    160 }
    161 #endif
    162164
    163165#endif
  • uspace/lib/c/include/vfs/vfs.h

    r4d51c60 rbc56f30  
    4444#include <async.h>
    4545#include <offset.h>
    46 
    47 #define VFS_MAX_OPEN_FILES  128
    4846
    4947enum vfs_change_state_type {
Note: See TracChangeset for help on using the changeset viewer.