Changeset 4e6a610 in mainline for uspace/lib/c/generic/stdio.c


Ignore:
Timestamp:
2018-06-25T09:54:28Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bfe90b6
Parents:
fb0ec570
git-author:
Jiri Svoboda <jiri@…> (2018-06-24 17:51:54)
git-committer:
Jiri Svoboda <jiri@…> (2018-06-25 09:54:28)
Message:

Temporary file functions rework. Fix libposix access() not working on directories.

File:
1 edited

Legend:

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

    rfb0ec570 r4e6a610  
    3434
    3535#include <errno.h>
     36#include <stdbool.h>
    3637#include <stdio.h>
     38#include <str.h>
    3739#include <str_error.h>
     40#include <tmpfile.h>
    3841#include <vfs/vfs.h>
     42
     43/** Static buffer for tmpnam function */
     44static char tmpnam_buf[L_tmpnam];
    3945
    4046/** Get stream position.
     
    8288        rc = vfs_rename_path(old_path, new_path);
    8389        if (rc != EOK) {
     90                /*
     91                 * Note that ISO C leaves the value of errno undefined,
     92                 * whereas according to UN*X standards, it is set.
     93                 */
    8494                errno = rc;
    8595                return -1;
     
    96106        rc = vfs_unlink_path(path);
    97107        if (rc != EOK) {
     108                /*
     109                 * Note that ISO C leaves the value of errno undefined,
     110                 * whereas according to UN*X standards, it is set.
     111                 */
    98112                errno = rc;
    99113                return -1;
     
    101115
    102116        return 0;
     117}
     118
     119/** Create a temporary file.
     120 *
     121 * @return Open stream descriptor or @c NULL on error. In that case
     122 *         errno is set (UN*X). Note that ISO C leaves the value of errno
     123 *         undefined.
     124 */
     125FILE *tmpfile(void)
     126{
     127        int file;
     128        FILE *stream;
     129
     130        file = __tmpfile();
     131        if (file < 0) {
     132                printf("file is < 0\n");
     133                errno = EEXIST;
     134                return NULL;
     135        }
     136
     137        stream = fdopen(file, "w+");
     138        if (stream == NULL) {
     139                printf("stream = NULL\n");
     140                vfs_put(file);
     141                errno = EACCES;
     142                return NULL;
     143        }
     144
     145        printf("returning stream\n");
     146        return stream;
     147}
     148
     149/** Create name for a temporary file.
     150 *
     151 * @param s Pointer to array of at least L_tmpnam bytes or @c NULL.
     152 * @return The pointer @a s or pointer to internal static buffer on success,
     153 *         @c NULL on error.
     154 */
     155char *tmpnam(char *s)
     156{
     157        char *p;
     158
     159        p = (s != NULL) ? s : tmpnam_buf;
     160        return __tmpnam(p);
    103161}
    104162
     
    115173}
    116174
     175
    117176/** @}
    118177 */
Note: See TracChangeset for help on using the changeset viewer.