Changeset 7f9df7b9 in mainline for uspace/lib/posix/src/stdio.c


Ignore:
Timestamp:
2018-01-22T22:42:57Z (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:
7a08c70
Parents:
e0f47f5
Message:

Remove unnecessary symbol renaming from libposix.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/src/stdio.c

    re0f47f5 r7f9df7b9  
    3434 */
    3535
    36 #define LIBPOSIX_INTERNAL
    37 #define __POSIX_DEF__(x) posix_##x
    38 
    3936#include "internal/common.h"
    4037#include "posix/stdio.h"
     
    5552#include "libc/adt/list.h"
    5653
    57 /** Clears the stream's error and end-of-file indicators.
    58  *
    59  * @param stream Stream whose indicators shall be cleared.
    60  */
    61 void posix_clearerr(FILE *stream)
    62 {
    63         clearerr(stream);
    64 }
    65 
    6654/**
    6755 * Generate a pathname for the controlling terminal.
     
    7058 * @return Either s or static location filled with the requested pathname.
    7159 */
    72 char *posix_ctermid(char *s)
     60char *ctermid(char *s)
    7361{
    7462        /* Currently always returns an error value (empty string). */
     
    8371        s[0] = '\0';
    8472        return s;
    85 }
    86 
    87 /**
    88  * Put a string on the stream.
    89  *
    90  * @param s String to be written.
    91  * @param stream Output stream.
    92  * @return Non-negative on success, EOF on failure.
    93  */
    94 int posix_fputs(const char *restrict s, FILE *restrict stream)
    95 {
    96         return fputs(s, stream);
    97 }
    98 
    99 /**
    100  * Push byte back into input stream.
    101  *
    102  * @param c Byte to be pushed back.
    103  * @param stream Stream to where the byte shall be pushed.
    104  * @return Provided byte on success or EOF if not possible.
    105  */
    106 int posix_ungetc(int c, FILE *stream)
    107 {
    108         return ungetc(c, stream);
    10973}
    11074
     
    12286 *     or -1 on error (set in errno).
    12387 */
    124 ssize_t posix_getdelim(char **restrict lineptr, size_t *restrict n,
     88ssize_t getdelim(char **restrict lineptr, size_t *restrict n,
    12589    int delimiter, FILE *restrict stream)
    12690{
     
    194158 *     or -1 on error (set in errno).
    195159 */
    196 ssize_t posix_getline(char **restrict lineptr, size_t *restrict n,
     160ssize_t getline(char **restrict lineptr, size_t *restrict n,
    197161    FILE *restrict stream)
    198162{
    199         return posix_getdelim(lineptr, n, '\n', stream);
    200 }
    201 
    202 /**
    203  * Reopen a file stream.
    204  *
    205  * @param filename Pathname of a file to be reopened or NULL for changing
    206  *     the mode of the stream.
    207  * @param mode Mode to be used for reopening the file or changing current
    208  *     mode of the stream.
    209  * @param stream Current stream associated with the opened file.
    210  * @return On success, either a stream of the reopened file or the provided
    211  *     stream with a changed mode. NULL otherwise.
    212  */
    213 FILE *posix_freopen(const char *restrict filename,
    214     const char *restrict mode, FILE *restrict stream)
    215 {
    216         return freopen(filename, mode, stream);
     163        return getdelim(lineptr, n, '\n', stream);
    217164}
    218165
     
    222169 * @param s Error message.
    223170 */
    224 void posix_perror(const char *s)
     171void perror(const char *s)
    225172{
    226173        if (s == NULL || s[0] == '\0') {
    227                 fprintf(stderr, "%s\n", posix_strerror(errno));
     174                fprintf(stderr, "%s\n", strerror(errno));
    228175        } else {
    229                 fprintf(stderr, "%s: %s\n", s, posix_strerror(errno));
     176                fprintf(stderr, "%s: %s\n", s, strerror(errno));
    230177        }
    231178}
     
    237184 * @return Zero on success, non-zero (with errno set) on failure
    238185 */
    239 int posix_fsetpos(FILE *stream, const posix_fpos_t *pos)
     186int fsetpos(FILE *stream, const fpos_t *pos)
    240187{
    241188        return fseek64(stream, pos->offset, SEEK_SET);
     
    248195 * @return Zero on success, non-zero (with errno set) on failure
    249196 */
    250 int posix_fgetpos(FILE *restrict stream, posix_fpos_t *restrict pos)
     197int fgetpos(FILE *restrict stream, fpos_t *restrict pos)
    251198{
    252199        off64_t ret = ftell64(stream);
     
    267214 * @return Zero on success, -1 otherwise.
    268215 */
    269 int posix_fseek(FILE *stream, long offset, int whence)
    270 {
    271         return fseek(stream, offset, whence);
    272 }
    273 
    274 /**
    275  * Reposition a file-position indicator in a stream.
    276  *
    277  * @param stream Stream to seek in.
    278  * @param offset Direction and amount of bytes to seek.
    279  * @param whence From where to seek.
    280  * @return Zero on success, -1 otherwise.
    281  */
    282 int posix_fseeko(FILE *stream, posix_off_t offset, int whence)
     216int fseeko(FILE *stream, off_t offset, int whence)
    283217{
    284218        return fseek64(stream, offset, whence);
     
    291225 * @return Current offset or -1 if not possible.
    292226 */
    293 long posix_ftell(FILE *stream)
    294 {
    295         return ftell(stream);
    296 }
    297 
    298 /**
    299  * Discover current file offset in a stream.
    300  *
    301  * @param stream Stream for which the offset shall be retrieved.
    302  * @return Current offset or -1 if not possible.
    303  */
    304 posix_off_t posix_ftello(FILE *stream)
     227off_t ftello(FILE *stream)
    305228{
    306229        return ftell64(stream);
     
    308231
    309232/**
    310  * Discard prefetched data or write unwritten data.
    311  *
    312  * @param stream Stream that shall be flushed.
    313  * @return Zero on success, EOF on failure.
    314  */
    315 int posix_fflush(FILE *stream)
    316 {
    317         return fflush(stream);
    318 }
    319 
    320 /**
    321233 * Print formatted output to the opened file.
    322234 *
     
    325237 * @return Either the number of printed characters or negative value on error.
    326238 */
    327 int posix_dprintf(int fildes, const char *restrict format, ...)
     239int dprintf(int fildes, const char *restrict format, ...)
    328240{
    329241        va_list list;
    330242        va_start(list, format);
    331         int result = posix_vdprintf(fildes, format, list);
     243        int result = vdprintf(fildes, format, list);
    332244        va_end(list);
    333245        return result;
     
    392304 * @return Either the number of printed characters or negative value on error.
    393305 */
    394 int posix_vdprintf(int fildes, const char *restrict format, va_list ap)
     306int vdprintf(int fildes, const char *restrict format, va_list ap)
    395307{
    396308        printf_spec_t spec = {
     
    411323 *     negative value on error.
    412324 */
    413 int posix_sprintf(char *s, const char *restrict format, ...)
     325int sprintf(char *s, const char *restrict format, ...)
    414326{
    415327        va_list list;
    416328        va_start(list, format);
    417         int result = posix_vsprintf(s, format, list);
     329        int result = vsprintf(s, format, list);
    418330        va_end(list);
    419331        return result;
     
    429341 *     negative value on error.
    430342 */
    431 int posix_vsprintf(char *s, const char *restrict format, va_list ap)
     343int vsprintf(char *s, const char *restrict format, va_list ap)
    432344{
    433345        return vsnprintf(s, STR_NO_LIMIT, format, ap);
     
    441353 * @return The number of converted output items or EOF on failure.
    442354 */
    443 int posix_fscanf(FILE *restrict stream, const char *restrict format, ...)
     355int fscanf(FILE *restrict stream, const char *restrict format, ...)
    444356{
    445357        va_list list;
    446358        va_start(list, format);
    447         int result = posix_vfscanf(stream, format, list);
     359        int result = vfscanf(stream, format, list);
    448360        va_end(list);
    449361        return result;
     
    456368 * @return The number of converted output items or EOF on failure.
    457369 */
    458 int posix_scanf(const char *restrict format, ...)
     370int scanf(const char *restrict format, ...)
    459371{
    460372        va_list list;
    461373        va_start(list, format);
    462         int result = posix_vscanf(format, list);
     374        int result = vscanf(format, list);
    463375        va_end(list);
    464376        return result;
     
    472384 * @return The number of converted output items or EOF on failure.
    473385 */
    474 int posix_vscanf(const char *restrict format, va_list arg)
    475 {
    476         return posix_vfscanf(stdin, format, arg);
     386int vscanf(const char *restrict format, va_list arg)
     387{
     388        return vfscanf(stdin, format, arg);
    477389}
    478390
     
    484396 * @return The number of converted output items or EOF on failure.
    485397 */
    486 int posix_sscanf(const char *restrict s, const char *restrict format, ...)
     398int sscanf(const char *restrict s, const char *restrict format, ...)
    487399{
    488400        va_list list;
    489401        va_start(list, format);
    490         int result = posix_vsscanf(s, format, list);
     402        int result = vsscanf(s, format, list);
    491403        va_end(list);
    492404        return result;
     
    498410 * @param file File stream to lock.
    499411 */
    500 void posix_flockfile(FILE *file)
     412void flockfile(FILE *file)
    501413{
    502414        /* dummy */
     
    509421 * @return Zero for success and non-zero if the lock cannot be acquired.
    510422 */
    511 int posix_ftrylockfile(FILE *file)
     423int ftrylockfile(FILE *file)
    512424{
    513425        /* dummy */
     
    520432 * @param file File stream to unlock.
    521433 */
    522 void posix_funlockfile(FILE *file)
     434void funlockfile(FILE *file)
    523435{
    524436        /* dummy */
     
    531443 * @return Either read byte or EOF.
    532444 */
    533 int posix_getc_unlocked(FILE *stream)
     445int getc_unlocked(FILE *stream)
    534446{
    535447        return getc(stream);
     
    541453 * @return Either read byte or EOF.
    542454 */
    543 int posix_getchar_unlocked(void)
     455int getchar_unlocked(void)
    544456{
    545457        return getchar();
     
    553465 * @return Either written byte or EOF.
    554466 */
    555 int posix_putc_unlocked(int c, FILE *stream)
     467int putc_unlocked(int c, FILE *stream)
    556468{
    557469        return putc(c, stream);
     
    564476 * @return Either written byte or EOF.
    565477 */
    566 int posix_putchar_unlocked(int c)
     478int putchar_unlocked(int c)
    567479{
    568480        return putchar(c);
    569 }
    570 
    571 /**
    572  * Remove a file or directory.
    573  *
    574  * @param path Pathname of the file that shall be removed.
    575  * @return Zero on success, -1 (with errno set) otherwise.
    576  */
    577 int posix_remove(const char *path)
    578 {
    579         if (failed(vfs_unlink_path(path)))
    580                 return -1;
    581         else
    582                 return 0;
    583 }
    584 
    585 /**
    586  * Rename a file or directory.
    587  *
    588  * @param old Old pathname.
    589  * @param new New pathname.
    590  * @return Zero on success, -1 (with errno set) otherwise.
    591  */
    592 int posix_rename(const char *old, const char *new)
    593 {
    594         if (failed(vfs_rename_path(old, new)))
    595                 return -1;
    596         else
    597                 return 0;
    598481}
    599482
     
    604487 * @return The value of s on success, NULL on failure.
    605488 */
    606 char *posix_tmpnam(char *s)
    607 {
    608         assert(L_tmpnam >= posix_strlen("/tmp/tnXXXXXX"));
     489char *tmpnam(char *s)
     490{
     491        assert(L_tmpnam >= strlen("/tmp/tnXXXXXX"));
    609492       
    610493        static char buffer[L_tmpnam + 1];
     
    613496        }
    614497       
    615         posix_strcpy(s, "/tmp/tnXXXXXX");
    616         posix_mktemp(s);
     498        strcpy(s, "/tmp/tnXXXXXX");
     499        mktemp(s);
    617500       
    618501        if (*s == '\0') {
     
    631514 * @return Newly allocated unique path for temporary file. NULL on failure.
    632515 */
    633 char *posix_tempnam(const char *dir, const char *pfx)
     516char *tempnam(const char *dir, const char *pfx)
    634517{
    635518        /* Sequence number of the filename. */
    636519        static int seq = 0;
    637520       
    638         size_t dir_len = posix_strlen(dir);
     521        size_t dir_len = strlen(dir);
    639522        if (dir[dir_len - 1] == '/') {
    640523                dir_len--;
    641524        }
    642525       
    643         size_t pfx_len = posix_strlen(pfx);
     526        size_t pfx_len = strlen(pfx);
    644527        if (pfx_len > 5) {
    645528                pfx_len = 5;
     
    655538       
    656539        char *res_ptr = result;
    657         posix_strncpy(res_ptr, dir, dir_len);
     540        strncpy(res_ptr, dir, dir_len);
    658541        res_ptr += dir_len;
    659         posix_strncpy(res_ptr, pfx, pfx_len);
     542        strncpy(res_ptr, pfx, pfx_len);
    660543        res_ptr += pfx_len;
    661544       
     
    666549                errno = EOK;
    667550                /* Check if the file exists. */
    668                 if (posix_access(result, F_OK) == -1) {
     551                if (access(result, F_OK) == -1) {
    669552                        if (errno == ENOENT) {
    670553                                errno = orig_errno;
     
    694577 * @return Newly allocated unique path for temporary file. NULL on failure.
    695578 */
    696 FILE *posix_tmpfile(void)
     579FILE *tmpfile(void)
    697580{
    698581        char filename[] = "/tmp/tfXXXXXX";
    699         int fd = posix_mkstemp(filename);
     582        int fd = mkstemp(filename);
    700583        if (fd == -1) {
    701584                /* errno set by mkstemp(). */
     
    704587       
    705588        /* Unlink the created file, so that it's removed on close(). */
    706         posix_unlink(filename);
     589        unlink(filename);
    707590        return fdopen(fd, "w+");
    708591}
Note: See TracChangeset for help on using the changeset viewer.