Changeset 777832e in mainline for uspace/lib/c/generic/stdio.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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 */
Note: See TracChangeset for help on using the changeset viewer.