Changeset 777832e in mainline for uspace/lib/c


Ignore:
Timestamp:
2018-06-21T12:27:09Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
296890f3
Parents:
7d7bc09
git-author:
Jiri Svoboda <jiri@…> (2018-06-20 19:26:46)
git-committer:
Jiri Svoboda <jiri@…> (2018-06-21 12:27:09)
Message:

fgetpos, fsetpos, perror.

Location:
uspace/lib/c
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    r7d7bc09 r777832e  
    194194        test/qsort.c \
    195195        test/sprintf.c \
     196        test/stdio.c \
    196197        test/stdlib.c \
    197198        test/str.c
  • uspace/lib/c/generic/stdio.c

    r7d7bc09 r777832e  
    11/*
    2  * Copyright (c) 2017 Jiri Svoboda
     2 * Copyright (c) 2018 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3535#include <errno.h>
    3636#include <stdio.h>
     37#include <str_error.h>
    3738#include <vfs/vfs.h>
     39
     40/** Get stream position.
     41 *
     42 * @param stream Stream
     43 * @param pos Place to store position
     44 *
     45 * @return Zero on success, non-zero on failure
     46 */
     47int fgetpos(FILE *stream, fpos_t *pos)
     48{
     49        off64_t p;
     50
     51        p = ftell64(stream);
     52        if (p < 0)
     53                return -1;
     54
     55        pos->pos = p;
     56        return 0;
     57}
     58
     59/** Get stream position.
     60 *
     61 * @param stream Stream
     62 * @param pos Position
     63 *
     64 * @return Zero on sucess, non-zero on failure
     65 */
     66int fsetpos(FILE *stream, const fpos_t *pos)
     67{
     68        int rc;
     69
     70        rc = fseek64(stream, pos->pos, SEEK_SET);
     71        if (rc < 0)
     72                return -1;
     73
     74        return 0;
     75}
    3876
    3977/** Rename file or directory (C standard) */
     
    65103}
    66104
     105/** Print error message and string representation of @c errno.
     106 *
     107 * @param s Error message
     108 */
     109void perror(const char *s)
     110{
     111        if (s != NULL && *s != '\0')
     112                fprintf(stderr, "%s: %s\n", s, str_error(errno));
     113        else
     114                fprintf(stderr, "%s\n", str_error(errno));
     115}
     116
    67117/** @}
    68118 */
  • uspace/lib/c/include/stdio.h

    r7d7bc09 r777832e  
    11/*
    22 * Copyright (c) 2005 Martin Decky
     3 * Copyright (c) 2018 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    3637#define LIBC_STDIO_H_
    3738
     39#include <offset.h>
    3840#include <stdarg.h>
    3941#include <io/verify.h>
     
    5961#define BUFSIZ  4096
    6062
     63/** Max number of files that is guaranteed to be able to open at the same time */
     64#define FOPEN_MAX VFS_MAX_OPEN_FILES
     65
    6166/** Recommended size of fixed-size array for holding file names. */
    6267#define FILENAME_MAX 4096
     
    6570struct _IO_FILE;
    6671typedef struct _IO_FILE FILE;
     72
     73/** File position */
     74typedef struct {
     75        off64_t pos;
     76} fpos_t;
    6777
    6878extern FILE *stdin;
     
    124134extern size_t fwrite(const void *, size_t, size_t, FILE *);
    125135
     136extern int fgetpos(FILE *, fpos_t *);
     137extern int fsetpos(FILE *, const fpos_t *);
     138
    126139extern int fseek(FILE *, long, int);
    127140extern void rewind(FILE *);
     
    132145extern int ferror(FILE *);
    133146extern void clearerr(FILE *);
     147
     148extern void perror(const char *);
    134149
    135150extern void setvbuf(FILE *, void *, int, size_t);
  • uspace/lib/c/include/vfs/vfs.h

    r7d7bc09 r777832e  
    4545#include <offset.h>
    4646
    47 #define MAX_OPEN_FILES  128
     47#define VFS_MAX_OPEN_FILES      128
    4848
    4949enum vfs_change_state_type {
Note: See TracChangeset for help on using the changeset viewer.