Changeset 2b3dd78 in mainline for uspace/lib/c/generic


Ignore:
Timestamp:
2018-01-31T12:02:00Z (8 years ago)
Author:
Jenda <jenda.jzqk73@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5595841
Parents:
a0a9cc2 (diff), 14d789c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge remote-tracking branch 'upstream/master' into forwardport

change tmon includes because of new stdlib

Location:
uspace/lib/c/generic
Files:
1 added
15 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/getopt.c

    ra0a9cc2 r2b3dd78  
    4949int     optopt = '?';           /* character checked for validity */
    5050int     optreset;               /* reset getopt */
    51 const char *optarg;             /* argument associated with option */
     51char    *optarg;                /* argument associated with option */
    5252
    5353
     
    6767#define INORDER (int)1
    6868
    69 #define EMSG    ""
     69static char EMSG[] = "";
    7070
    7171static int getopt_internal(int, char **, const char *);
     
    7373static void permute_args(int, int, int, char **);
    7474
    75 static const char *place = EMSG; /* option letter processing */
     75static char *place = EMSG; /* option letter processing */
    7676
    7777/* XXX: set optreset to 1 rather than these two */
     
    336336        if (retval == -2) {
    337337                char *current_argv;
    338                 const char *has_equal;
     338                char *has_equal;
    339339                size_t current_argv_len;
    340340                int i, ambiguous, match;
  • uspace/lib/c/generic/inet/addr.c

    ra0a9cc2 r2b3dd78  
    4242#include <bitops.h>
    4343#include <inttypes.h>
     44#include <str.h>
    4445
    4546#define INET_PREFIXSTRSIZE  5
  • uspace/lib/c/generic/io/io.c

    ra0a9cc2 r2b3dd78  
    799799}
    800800
    801 int fseek(FILE *stream, long offset, int whence)
     801int fseek64(FILE *stream, off64_t offset, int whence)
    802802{
    803803        errno_t rc;
     
    814814        stream->ungetc_chars = 0;
    815815
    816         struct stat st;
     816        vfs_stat_t st;
    817817        switch (whence) {
    818818        case SEEK_SET:
     
    837837}
    838838
    839 long ftell(FILE *stream)
    840 {
    841         /* The native position is too large for the C99-ish interface. */
    842         if (stream->pos - stream->ungetc_chars > LONG_MAX)
    843                 return EOF;
    844 
     839off64_t ftell64(FILE *stream)
     840{
    845841        if (stream->error)
    846842                return EOF;
     
    853849
    854850        return stream->pos - stream->ungetc_chars;
     851}
     852
     853int fseek(FILE *stream, long offset, int whence)
     854{
     855        return fseek64(stream, offset, whence);
     856}
     857
     858long ftell(FILE *stream)
     859{
     860        off64_t off = ftell64(stream);
     861
     862        /* The native position is too large for the C99-ish interface. */
     863        if (off > LONG_MAX)
     864                return EOF;
     865
     866        return off;
    855867}
    856868
  • uspace/lib/c/generic/io/log.c

    ra0a9cc2 r2b3dd78  
    4141#include <io/log.h>
    4242#include <ipc/logger.h>
     43#include <str.h>
    4344#include <ns.h>
    4445
  • uspace/lib/c/generic/io/table.c

    ra0a9cc2 r2b3dd78  
    4040#include <stdio.h>
    4141#include <stdlib.h>
     42#include <str.h>
    4243
    4344static table_column_t *table_column_first(table_t *);
  • uspace/lib/c/generic/malloc.c

    ra0a9cc2 r2b3dd78  
    3333/** @file
    3434 */
    35 
    36 #define _HELENOS_SOURCE
    3735
    3836#include <malloc.h>
     
    876874 *
    877875 */
    878 void *realloc(const void *addr, const size_t size)
    879 {
     876void *realloc(void * const addr, const size_t size)
     877{
     878        if (size == 0) {
     879                free(addr);
     880                return NULL;
     881        }
     882
    880883        if (addr == NULL)
    881884                return malloc(size);
     
    985988 *
    986989 */
    987 void free(const void *addr)
     990void free(void * const addr)
    988991{
    989992        if (addr == NULL)
  • uspace/lib/c/generic/rtld/dynamic.c

    ra0a9cc2 r2b3dd78  
    3737#include <stdio.h>
    3838#include <inttypes.h>
     39#include <str.h>
    3940
    4041#include <rtld/elf_dyn.h>
  • uspace/lib/c/generic/rtld/module.c

    ra0a9cc2 r2b3dd78  
    4141#include <stdio.h>
    4242#include <stdlib.h>
     43#include <str.h>
    4344
    4445#include <rtld/rtld.h>
  • uspace/lib/c/generic/rtld/rtld.c

    ra0a9cc2 r2b3dd78  
    4040#include <rtld/rtld_debug.h>
    4141#include <stdlib.h>
     42#include <str.h>
    4243
    4344rtld_t *runtime_env;
  • uspace/lib/c/generic/rtld/symbol.c

    ra0a9cc2 r2b3dd78  
    3737#include <stdio.h>
    3838#include <stdlib.h>
     39#include <str.h>
    3940
    4041#include <elf/elf.h>
  • uspace/lib/c/generic/stdlib.c

    ra0a9cc2 r2b3dd78  
    3535#include <stdlib.h>
    3636
    37 static long glbl_seed = 1;
     37static int glbl_seed = 1;
    3838
    39 long int random(void)
     39int rand(void)
    4040{
    4141        return glbl_seed = ((1366 * glbl_seed + 150889) % RAND_MAX);
    4242}
    4343
    44 void srandom(unsigned int seed)
     44void srand(unsigned int seed)
    4545{
    4646        glbl_seed = seed % RAND_MAX;
  • uspace/lib/c/generic/str.c

    ra0a9cc2 r2b3dd78  
    12731273}
    12741274
    1275 /** Convert string to a number.
    1276  * Core of strtol and strtoul functions.
    1277  *
    1278  * @param nptr          Pointer to string.
    1279  * @param endptr        If not NULL, function stores here pointer to the first
    1280  *                      invalid character.
    1281  * @param base          Zero or number between 2 and 36 inclusive.
    1282  * @param sgn           It's set to 1 if minus found.
    1283  * @return              Result of conversion.
    1284  */
    1285 static unsigned long
    1286 _strtoul(const char *nptr, char **endptr, int base, char *sgn)
    1287 {
    1288         unsigned char c;
    1289         unsigned long result = 0;
    1290         unsigned long a, b;
    1291         const char *str = nptr;
    1292         const char *tmpptr;
    1293        
    1294         while (isspace(*str))
    1295                 str++;
    1296        
    1297         if (*str == '-') {
    1298                 *sgn = 1;
    1299                 ++str;
    1300         } else if (*str == '+')
    1301                 ++str;
    1302        
    1303         if (base) {
    1304                 if ((base == 1) || (base > 36)) {
    1305                         /* FIXME: set errno to EINVAL */
    1306                         return 0;
    1307                 }
    1308                 if ((base == 16) && (*str == '0') && ((str[1] == 'x') ||
    1309                     (str[1] == 'X'))) {
    1310                         str += 2;
    1311                 }
    1312         } else {
    1313                 base = 10;
    1314                
    1315                 if (*str == '0') {
    1316                         base = 8;
    1317                         if ((str[1] == 'X') || (str[1] == 'x'))  {
    1318                                 base = 16;
    1319                                 str += 2;
    1320                         }
    1321                 }
    1322         }
    1323        
    1324         tmpptr = str;
    1325 
    1326         while (*str) {
    1327                 c = *str;
    1328                 c = (c >= 'a' ? c - 'a' + 10 : (c >= 'A' ? c - 'A' + 10 :
    1329                     (c <= '9' ? c - '0' : 0xff)));
    1330                 if (c >= base) {
    1331                         break;
    1332                 }
    1333                
    1334                 a = (result & 0xff) * base + c;
    1335                 b = (result >> 8) * base + (a >> 8);
    1336                
    1337                 if (b > (ULONG_MAX >> 8)) {
    1338                         /* overflow */
    1339                         /* FIXME: errno = ERANGE*/
    1340                         return ULONG_MAX;
    1341                 }
    1342        
    1343                 result = (b << 8) + (a & 0xff);
    1344                 ++str;
    1345         }
    1346        
    1347         if (str == tmpptr) {
    1348                 /*
    1349                  * No number was found => first invalid character is the first
    1350                  * character of the string.
    1351                  */
    1352                 /* FIXME: set errno to EINVAL */
    1353                 str = nptr;
    1354                 result = 0;
    1355         }
    1356        
    1357         if (endptr)
    1358                 *endptr = (char *) str;
    1359 
    1360         if (nptr == str) {
    1361                 /*FIXME: errno = EINVAL*/
    1362                 return 0;
    1363         }
    1364 
    1365         return result;
    1366 }
    1367 
    1368 /** Convert initial part of string to long int according to given base.
    1369  * The number may begin with an arbitrary number of whitespaces followed by
    1370  * optional sign (`+' or `-'). If the base is 0 or 16, the prefix `0x' may be
    1371  * inserted and the number will be taken as hexadecimal one. If the base is 0
    1372  * and the number begin with a zero, number will be taken as octal one (as with
    1373  * base 8). Otherwise the base 0 is taken as decimal.
    1374  *
    1375  * @param nptr          Pointer to string.
    1376  * @param endptr        If not NULL, function stores here pointer to the first
    1377  *                      invalid character.
    1378  * @param base          Zero or number between 2 and 36 inclusive.
    1379  * @return              Result of conversion.
    1380  */
    1381 long int strtol(const char *nptr, char **endptr, int base)
    1382 {
    1383         char sgn = 0;
    1384         unsigned long number = 0;
    1385        
    1386         number = _strtoul(nptr, endptr, base, &sgn);
    1387 
    1388         if (number > LONG_MAX) {
    1389                 if ((sgn) && (number == (unsigned long) (LONG_MAX) + 1)) {
    1390                         /* FIXME: set 0 to errno */
    1391                         return number;
    1392                 }
    1393                 /* FIXME: set ERANGE to errno */
    1394                 return (sgn ? LONG_MIN : LONG_MAX);
    1395         }
    1396        
    1397         return (sgn ? -number : number);
    1398 }
    13991275
    14001276/** Duplicate string.
     
    14571333        str_ncpy(dest, size + 1, src, size);
    14581334        return dest;
    1459 }
    1460 
    1461 /** Convert initial part of string to unsigned long according to given base.
    1462  * The number may begin with an arbitrary number of whitespaces followed by
    1463  * optional sign (`+' or `-'). If the base is 0 or 16, the prefix `0x' may be
    1464  * inserted and the number will be taken as hexadecimal one. If the base is 0
    1465  * and the number begin with a zero, number will be taken as octal one (as with
    1466  * base 8). Otherwise the base 0 is taken as decimal.
    1467  *
    1468  * @param nptr          Pointer to string.
    1469  * @param endptr        If not NULL, function stores here pointer to the first
    1470  *                      invalid character
    1471  * @param base          Zero or number between 2 and 36 inclusive.
    1472  * @return              Result of conversion.
    1473  */
    1474 unsigned long strtoul(const char *nptr, char **endptr, int base)
    1475 {
    1476         char sgn = 0;
    1477         unsigned long number = 0;
    1478        
    1479         number = _strtoul(nptr, endptr, base, &sgn);
    1480 
    1481         return (sgn ? -number : number);
    14821335}
    14831336
  • uspace/lib/c/generic/uuid.c

    ra0a9cc2 r2b3dd78  
    5252        /* XXX This is a rather poor way of generating random numbers */
    5353        gettimeofday(&tv, NULL);
    54         srandom(tv.tv_sec ^ tv.tv_usec);
     54        srand(tv.tv_sec ^ tv.tv_usec);
    5555
    5656        for (i = 0; i < uuid_bytes; i++)
    57                 uuid->b[i] = random();
     57                uuid->b[i] = rand();
    5858
    5959        /* Version 4 UUID from random or pseudo-random numbers */
  • uspace/lib/c/generic/vfs/mtab.c

    ra0a9cc2 r2b3dd78  
    4040#include <errno.h>
    4141#include <assert.h>
     42#include <str.h>
    4243
    43 static void process_mp(const char *path, struct stat *stat, list_t *mtab_list)
     44static void process_mp(const char *path, vfs_stat_t *stat, list_t *mtab_list)
    4445{
    4546        mtab_ent_t *ent;
     
    5354        ent->service_id = stat->service_id;
    5455
    55         struct statfs stfs;
     56        vfs_statfs_t stfs;
    5657        if (vfs_statfs_path(path, &stfs) == EOK)
    5758                str_cpy(ent->fs_name, sizeof(ent->fs_name), stfs.fs_name);
     
    7475        while ((dirent = readdir(dir)) != NULL) {
    7576                char *child;
    76                 struct stat st;
     77                vfs_stat_t st;
    7778                errno_t rc;
    7879                int ret;
     
    122123errno_t vfs_get_mtab_list(list_t *mtab_list)
    123124{
    124         struct stat st;
     125        vfs_stat_t st;
    125126
    126127        errno_t rc = vfs_stat_path("/", &st);
  • uspace/lib/c/generic/vfs/vfs.c

    ra0a9cc2 r2b3dd78  
    352352async_sess_t *vfs_fd_session(int file, iface_t iface)
    353353{
    354         struct stat stat;
     354        vfs_stat_t stat;
    355355        errno_t rc = vfs_stat(file, &stat);
    356356        if (rc != EOK)
     
    10521052 * @return              EOK on success or an error code
    10531053 */
    1054 errno_t vfs_stat(int file, struct stat *stat)
     1054errno_t vfs_stat(int file, vfs_stat_t *stat)
    10551055{
    10561056        errno_t rc;
     
    10601060       
    10611061        req = async_send_1(exch, VFS_IN_STAT, file, NULL);
    1062         rc = async_data_read_start(exch, (void *) stat, sizeof(struct stat));
     1062        rc = async_data_read_start(exch, (void *) stat, sizeof(vfs_stat_t));
    10631063        if (rc != EOK) {
    10641064                vfs_exchange_end(exch);
     
    10861086 * @return              EOK on success or an error code
    10871087 */
    1088 errno_t vfs_stat_path(const char *path, struct stat *stat)
     1088errno_t vfs_stat_path(const char *path, vfs_stat_t *stat)
    10891089{
    10901090        int file;
     
    11071107 * @return              EOK on success or an error code
    11081108 */
    1109 errno_t vfs_statfs(int file, struct statfs *st)
     1109errno_t vfs_statfs(int file, vfs_statfs_t *st)
    11101110{
    11111111        errno_t rc, ret;
     
    11321132 * @return              EOK on success or an error code
    11331133 */
    1134 errno_t vfs_statfs_path(const char *path, struct statfs *st)
     1134errno_t vfs_statfs_path(const char *path, vfs_statfs_t *st)
    11351135{
    11361136        int file;
Note: See TracChangeset for help on using the changeset viewer.