[b861b58] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2005 Martin Decky
|
---|
[b861b58] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
[b2951e2] | 27 | */
|
---|
| 28 |
|
---|
[fadd381] | 29 | /** @addtogroup libc
|
---|
[b2951e2] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
[2595dab] | 33 | */
|
---|
[b861b58] | 34 |
|
---|
[cc6f688] | 35 | #include <stdio.h>
|
---|
[2595dab] | 36 | #include <unistd.h>
|
---|
[ef8bcc6] | 37 | #include <assert.h>
|
---|
[19f857a] | 38 | #include <str.h>
|
---|
[56fa418] | 39 | #include <errno.h>
|
---|
[3e6a98c5] | 40 | #include <stdbool.h>
|
---|
[2595dab] | 41 | #include <malloc.h>
|
---|
[64d2b10] | 42 | #include <async.h>
|
---|
[6fa9a99d] | 43 | #include <io/kio.h>
|
---|
[2595dab] | 44 | #include <vfs/vfs.h>
|
---|
[79ae36dd] | 45 | #include <vfs/vfs_sess.h>
|
---|
[bb9ec2d] | 46 | #include <vfs/inbox.h>
|
---|
[15f3c3f] | 47 | #include <ipc/loc.h>
|
---|
[d9c8c81] | 48 | #include <adt/list.h>
|
---|
[47b7006] | 49 | #include "../private/io.h"
|
---|
[79ae36dd] | 50 | #include "../private/stdio.h"
|
---|
[b861b58] | 51 |
|
---|
[facebd56] | 52 | static void _ffillbuf(FILE *stream);
|
---|
[ef8bcc6] | 53 | static void _fflushbuf(FILE *stream);
|
---|
| 54 |
|
---|
[a68f737] | 55 | static FILE stdin_null = {
|
---|
[2595dab] | 56 | .fd = -1,
|
---|
[58898d1d] | 57 | .pos = 0,
|
---|
[2595dab] | 58 | .error = true,
|
---|
| 59 | .eof = true,
|
---|
[6fa9a99d] | 60 | .kio = false,
|
---|
[79ae36dd] | 61 | .sess = NULL,
|
---|
[ef8bcc6] | 62 | .btype = _IONBF,
|
---|
| 63 | .buf = NULL,
|
---|
| 64 | .buf_size = 0,
|
---|
[facebd56] | 65 | .buf_head = NULL,
|
---|
| 66 | .buf_tail = NULL,
|
---|
[c70703a] | 67 | .buf_state = _bs_empty
|
---|
[2595dab] | 68 | };
|
---|
[350514c] | 69 |
|
---|
[6fa9a99d] | 70 | static FILE stdout_kio = {
|
---|
[2595dab] | 71 | .fd = -1,
|
---|
[58898d1d] | 72 | .pos = 0,
|
---|
[2595dab] | 73 | .error = false,
|
---|
| 74 | .eof = false,
|
---|
[6fa9a99d] | 75 | .kio = true,
|
---|
[79ae36dd] | 76 | .sess = NULL,
|
---|
[ef8bcc6] | 77 | .btype = _IOLBF,
|
---|
| 78 | .buf = NULL,
|
---|
| 79 | .buf_size = BUFSIZ,
|
---|
[facebd56] | 80 | .buf_head = NULL,
|
---|
| 81 | .buf_tail = NULL,
|
---|
| 82 | .buf_state = _bs_empty
|
---|
[2595dab] | 83 | };
|
---|
| 84 |
|
---|
[6fa9a99d] | 85 | static FILE stderr_kio = {
|
---|
[a68f737] | 86 | .fd = -1,
|
---|
[58898d1d] | 87 | .pos = 0,
|
---|
[a68f737] | 88 | .error = false,
|
---|
| 89 | .eof = false,
|
---|
[6fa9a99d] | 90 | .kio = true,
|
---|
[79ae36dd] | 91 | .sess = NULL,
|
---|
[ef8bcc6] | 92 | .btype = _IONBF,
|
---|
| 93 | .buf = NULL,
|
---|
| 94 | .buf_size = 0,
|
---|
[facebd56] | 95 | .buf_head = NULL,
|
---|
| 96 | .buf_tail = NULL,
|
---|
| 97 | .buf_state = _bs_empty
|
---|
[a68f737] | 98 | };
|
---|
| 99 |
|
---|
| 100 | FILE *stdin = NULL;
|
---|
| 101 | FILE *stdout = NULL;
|
---|
| 102 | FILE *stderr = NULL;
|
---|
| 103 |
|
---|
| 104 | static LIST_INITIALIZE(files);
|
---|
| 105 |
|
---|
[bb9ec2d] | 106 | void __stdio_init(void)
|
---|
[a68f737] | 107 | {
|
---|
[bb9ec2d] | 108 | /* The first three standard file descriptors are assigned for compatibility.
|
---|
| 109 | * This will probably be removed later.
|
---|
| 110 | */
|
---|
| 111 |
|
---|
| 112 | int infd = inbox_get("stdin");
|
---|
| 113 | if (infd >= 0) {
|
---|
[fcab7ef] | 114 | int stdinfd = vfs_clone(infd, -1, false);
|
---|
[bb9ec2d] | 115 | assert(stdinfd == 0);
|
---|
[b19e892] | 116 | vfs_open(stdinfd, MODE_READ);
|
---|
[bb9ec2d] | 117 | stdin = fdopen(stdinfd, "r");
|
---|
[a68f737] | 118 | } else {
|
---|
| 119 | stdin = &stdin_null;
|
---|
| 120 | list_append(&stdin->link, &files);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[bb9ec2d] | 123 | int outfd = inbox_get("stdout");
|
---|
| 124 | if (outfd >= 0) {
|
---|
[fcab7ef] | 125 | int stdoutfd = vfs_clone(outfd, -1, false);
|
---|
[bb9ec2d] | 126 | assert(stdoutfd <= 1);
|
---|
[fcab7ef] | 127 | while (stdoutfd < 1)
|
---|
| 128 | stdoutfd = vfs_clone(outfd, -1, false);
|
---|
[b19e892] | 129 | vfs_open(stdoutfd, MODE_APPEND);
|
---|
[bb9ec2d] | 130 | stdout = fdopen(stdoutfd, "a");
|
---|
[a68f737] | 131 | } else {
|
---|
[6fa9a99d] | 132 | stdout = &stdout_kio;
|
---|
[a68f737] | 133 | list_append(&stdout->link, &files);
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[bb9ec2d] | 136 | int errfd = inbox_get("stderr");
|
---|
| 137 | if (errfd >= 0) {
|
---|
[fcab7ef] | 138 | int stderrfd = vfs_clone(errfd, -1, false);
|
---|
[bb9ec2d] | 139 | assert(stderrfd <= 2);
|
---|
[fcab7ef] | 140 | while (stderrfd < 2)
|
---|
| 141 | stderrfd = vfs_clone(errfd, -1, false);
|
---|
[b19e892] | 142 | vfs_open(stderrfd, MODE_APPEND);
|
---|
[bb9ec2d] | 143 | stderr = fdopen(stderrfd, "a");
|
---|
[a68f737] | 144 | } else {
|
---|
[6fa9a99d] | 145 | stderr = &stderr_kio;
|
---|
[a68f737] | 146 | list_append(&stderr->link, &files);
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[db24058] | 150 | void __stdio_done(void)
|
---|
[a68f737] | 151 | {
|
---|
[b72efe8] | 152 | while (!list_empty(&files)) {
|
---|
| 153 | FILE *file = list_get_instance(list_first(&files), FILE, link);
|
---|
[a68f737] | 154 | fclose(file);
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
[2595dab] | 157 |
|
---|
[b19e892] | 158 | static bool parse_mode(const char *fmode, int *mode, bool *create, bool *truncate)
|
---|
[b861b58] | 159 | {
|
---|
[2595dab] | 160 | /* Parse mode except first character. */
|
---|
[b19e892] | 161 | const char *mp = fmode;
|
---|
[2595dab] | 162 | if (*mp++ == 0) {
|
---|
| 163 | errno = EINVAL;
|
---|
| 164 | return false;
|
---|
| 165 | }
|
---|
[cc6f688] | 166 |
|
---|
[2595dab] | 167 | if ((*mp == 'b') || (*mp == 't'))
|
---|
| 168 | mp++;
|
---|
[c9857c6] | 169 |
|
---|
[2595dab] | 170 | bool plus;
|
---|
| 171 | if (*mp == '+') {
|
---|
| 172 | mp++;
|
---|
| 173 | plus = true;
|
---|
| 174 | } else
|
---|
| 175 | plus = false;
|
---|
[566f4cfb] | 176 |
|
---|
[2595dab] | 177 | if (*mp != 0) {
|
---|
| 178 | errno = EINVAL;
|
---|
| 179 | return false;
|
---|
[350514c] | 180 | }
|
---|
[b19e892] | 181 |
|
---|
| 182 | *create = false;
|
---|
| 183 | *truncate = false;
|
---|
[350514c] | 184 |
|
---|
[b19e892] | 185 | /* Parse first character of fmode and determine mode for vfs_open(). */
|
---|
| 186 | switch (fmode[0]) {
|
---|
[2595dab] | 187 | case 'r':
|
---|
[b19e892] | 188 | *mode = plus ? MODE_READ | MODE_WRITE : MODE_READ;
|
---|
[2595dab] | 189 | break;
|
---|
| 190 | case 'w':
|
---|
[b19e892] | 191 | *mode = plus ? MODE_READ | MODE_WRITE : MODE_WRITE;
|
---|
| 192 | *create = true;
|
---|
| 193 | if (!plus)
|
---|
| 194 | *truncate = true;
|
---|
[2595dab] | 195 | break;
|
---|
| 196 | case 'a':
|
---|
| 197 | /* TODO: a+ must read from beginning, append to the end. */
|
---|
| 198 | if (plus) {
|
---|
| 199 | errno = ENOTSUP;
|
---|
| 200 | return false;
|
---|
| 201 | }
|
---|
[b19e892] | 202 |
|
---|
| 203 | *mode = MODE_APPEND | (plus ? MODE_READ | MODE_WRITE : MODE_WRITE);
|
---|
| 204 | *create = true;
|
---|
[82582e4] | 205 | break;
|
---|
[2595dab] | 206 | default:
|
---|
| 207 | errno = EINVAL;
|
---|
| 208 | return false;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | return true;
|
---|
[cc6f688] | 212 | }
|
---|
[b861b58] | 213 |
|
---|
[ef8bcc6] | 214 | /** Set stream buffer. */
|
---|
| 215 | void setvbuf(FILE *stream, void *buf, int mode, size_t size)
|
---|
| 216 | {
|
---|
| 217 | stream->btype = mode;
|
---|
| 218 | stream->buf = buf;
|
---|
| 219 | stream->buf_size = size;
|
---|
| 220 | stream->buf_head = stream->buf;
|
---|
[facebd56] | 221 | stream->buf_tail = stream->buf;
|
---|
| 222 | stream->buf_state = _bs_empty;
|
---|
[ef8bcc6] | 223 | }
|
---|
| 224 |
|
---|
[7699c21] | 225 | /** Set stream buffer.
|
---|
| 226 | *
|
---|
| 227 | * When @p buf is NULL, the stream is set as unbuffered, otherwise
|
---|
| 228 | * full buffering is enabled.
|
---|
| 229 | */
|
---|
| 230 | void setbuf(FILE *stream, void *buf)
|
---|
| 231 | {
|
---|
| 232 | if (buf == NULL) {
|
---|
| 233 | setvbuf(stream, NULL, _IONBF, BUFSIZ);
|
---|
| 234 | } else {
|
---|
| 235 | setvbuf(stream, buf, _IOFBF, BUFSIZ);
|
---|
| 236 | }
|
---|
| 237 | }
|
---|
| 238 |
|
---|
[bfd247f] | 239 | static void _setvbuf(FILE *stream)
|
---|
| 240 | {
|
---|
| 241 | /* FIXME: Use more complex rules for setting buffering options. */
|
---|
| 242 |
|
---|
| 243 | switch (stream->fd) {
|
---|
| 244 | case 1:
|
---|
| 245 | setvbuf(stream, NULL, _IOLBF, BUFSIZ);
|
---|
| 246 | break;
|
---|
| 247 | case 0:
|
---|
| 248 | case 2:
|
---|
| 249 | setvbuf(stream, NULL, _IONBF, 0);
|
---|
| 250 | break;
|
---|
| 251 | default:
|
---|
| 252 | setvbuf(stream, NULL, _IOFBF, BUFSIZ);
|
---|
| 253 | }
|
---|
| 254 | }
|
---|
| 255 |
|
---|
[ef8bcc6] | 256 | /** Allocate stream buffer. */
|
---|
| 257 | static int _fallocbuf(FILE *stream)
|
---|
| 258 | {
|
---|
| 259 | assert(stream->buf == NULL);
|
---|
[bfd247f] | 260 |
|
---|
[ef8bcc6] | 261 | stream->buf = malloc(stream->buf_size);
|
---|
| 262 | if (stream->buf == NULL) {
|
---|
| 263 | errno = ENOMEM;
|
---|
[6afc9d7] | 264 | return EOF;
|
---|
[ef8bcc6] | 265 | }
|
---|
[bfd247f] | 266 |
|
---|
[ef8bcc6] | 267 | stream->buf_head = stream->buf;
|
---|
[facebd56] | 268 | stream->buf_tail = stream->buf;
|
---|
[ef8bcc6] | 269 | return 0;
|
---|
| 270 | }
|
---|
| 271 |
|
---|
[2595dab] | 272 | /** Open a stream.
|
---|
| 273 | *
|
---|
| 274 | * @param path Path of the file to open.
|
---|
| 275 | * @param mode Mode string, (r|w|a)[b|t][+].
|
---|
| 276 | *
|
---|
[4e2cf8b] | 277 | */
|
---|
[b19e892] | 278 | FILE *fopen(const char *path, const char *fmode)
|
---|
[4e2cf8b] | 279 | {
|
---|
[b19e892] | 280 | int mode;
|
---|
| 281 | bool create;
|
---|
| 282 | bool truncate;
|
---|
| 283 |
|
---|
| 284 | if (!parse_mode(fmode, &mode, &create, &truncate))
|
---|
[2595dab] | 285 | return NULL;
|
---|
[4e2cf8b] | 286 |
|
---|
[2595dab] | 287 | /* Open file. */
|
---|
| 288 | FILE *stream = malloc(sizeof(FILE));
|
---|
| 289 | if (stream == NULL) {
|
---|
| 290 | errno = ENOMEM;
|
---|
| 291 | return NULL;
|
---|
| 292 | }
|
---|
[b19e892] | 293 |
|
---|
| 294 | int flags = WALK_REGULAR;
|
---|
| 295 | if (create)
|
---|
| 296 | flags |= WALK_MAY_CREATE;
|
---|
| 297 | int file = vfs_lookup(path, flags);
|
---|
| 298 | if (file < 0) {
|
---|
| 299 | errno = file;
|
---|
| 300 | free(stream);
|
---|
| 301 | return NULL;
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | int rc = vfs_open(file, mode);
|
---|
| 305 | if (rc != EOK) {
|
---|
| 306 | errno = rc;
|
---|
[9c4cf0d] | 307 | vfs_put(file);
|
---|
[2595dab] | 308 | free(stream);
|
---|
| 309 | return NULL;
|
---|
| 310 | }
|
---|
| 311 |
|
---|
[b19e892] | 312 | if (truncate) {
|
---|
| 313 | rc = vfs_resize(file, 0);
|
---|
| 314 | if (rc != EOK) {
|
---|
| 315 | errno = rc;
|
---|
[9c4cf0d] | 316 | vfs_put(file);
|
---|
[b19e892] | 317 | free(stream);
|
---|
| 318 | return NULL;
|
---|
| 319 | }
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | stream->fd = file;
|
---|
[58898d1d] | 323 | stream->pos = 0;
|
---|
[2595dab] | 324 | stream->error = false;
|
---|
| 325 | stream->eof = false;
|
---|
[6fa9a99d] | 326 | stream->kio = false;
|
---|
[79ae36dd] | 327 | stream->sess = NULL;
|
---|
[facebd56] | 328 | stream->need_sync = false;
|
---|
[bfd247f] | 329 | _setvbuf(stream);
|
---|
[e86a617a] | 330 | stream->ungetc_chars = 0;
|
---|
[2595dab] | 331 |
|
---|
[a68f737] | 332 | list_append(&stream->link, &files);
|
---|
| 333 |
|
---|
[2595dab] | 334 | return stream;
|
---|
| 335 | }
|
---|
| 336 |
|
---|
[080ad7f] | 337 | FILE *fdopen(int fd, const char *mode)
|
---|
| 338 | {
|
---|
| 339 | /* Open file. */
|
---|
| 340 | FILE *stream = malloc(sizeof(FILE));
|
---|
| 341 | if (stream == NULL) {
|
---|
| 342 | errno = ENOMEM;
|
---|
| 343 | return NULL;
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | stream->fd = fd;
|
---|
[58898d1d] | 347 | stream->pos = 0;
|
---|
[080ad7f] | 348 | stream->error = false;
|
---|
| 349 | stream->eof = false;
|
---|
[6fa9a99d] | 350 | stream->kio = false;
|
---|
[79ae36dd] | 351 | stream->sess = NULL;
|
---|
[facebd56] | 352 | stream->need_sync = false;
|
---|
[bfd247f] | 353 | _setvbuf(stream);
|
---|
[e86a617a] | 354 | stream->ungetc_chars = 0;
|
---|
[080ad7f] | 355 |
|
---|
| 356 | list_append(&stream->link, &files);
|
---|
| 357 |
|
---|
| 358 | return stream;
|
---|
| 359 | }
|
---|
| 360 |
|
---|
[80bee81] | 361 |
|
---|
| 362 | static int _fclose_nofree(FILE *stream)
|
---|
[2595dab] | 363 | {
|
---|
| 364 | int rc = 0;
|
---|
| 365 |
|
---|
| 366 | fflush(stream);
|
---|
| 367 |
|
---|
[79ae36dd] | 368 | if (stream->sess != NULL)
|
---|
| 369 | async_hangup(stream->sess);
|
---|
[2595dab] | 370 |
|
---|
| 371 | if (stream->fd >= 0)
|
---|
[9c4cf0d] | 372 | rc = vfs_put(stream->fd);
|
---|
[2595dab] | 373 |
|
---|
[a68f737] | 374 | list_remove(&stream->link);
|
---|
| 375 |
|
---|
[80bee81] | 376 | if (rc != 0) {
|
---|
| 377 | /* errno was set by close() */
|
---|
| 378 | return EOF;
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | return 0;
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | int fclose(FILE *stream)
|
---|
| 385 | {
|
---|
| 386 | int rc = _fclose_nofree(stream);
|
---|
| 387 |
|
---|
[a68f737] | 388 | if ((stream != &stdin_null)
|
---|
[6fa9a99d] | 389 | && (stream != &stdout_kio)
|
---|
| 390 | && (stream != &stderr_kio))
|
---|
[2595dab] | 391 | free(stream);
|
---|
| 392 |
|
---|
[80bee81] | 393 | return rc;
|
---|
| 394 | }
|
---|
| 395 |
|
---|
| 396 | FILE *freopen(const char *path, const char *mode, FILE *stream)
|
---|
| 397 | {
|
---|
| 398 | FILE *nstr;
|
---|
[2595dab] | 399 |
|
---|
[80bee81] | 400 | if (path == NULL) {
|
---|
| 401 | /* Changing mode is not supported */
|
---|
| 402 | return NULL;
|
---|
[2595dab] | 403 | }
|
---|
| 404 |
|
---|
[80bee81] | 405 | (void) _fclose_nofree(stream);
|
---|
| 406 | nstr = fopen(path, mode);
|
---|
| 407 | if (nstr == NULL) {
|
---|
| 408 | free(stream);
|
---|
| 409 | return NULL;
|
---|
| 410 | }
|
---|
| 411 |
|
---|
| 412 | list_remove(&nstr->link);
|
---|
| 413 | *stream = *nstr;
|
---|
| 414 | list_append(&stream->link, &files);
|
---|
| 415 |
|
---|
| 416 | free(nstr);
|
---|
| 417 |
|
---|
| 418 | return stream;
|
---|
[4e2cf8b] | 419 | }
|
---|
| 420 |
|
---|
[facebd56] | 421 | /** Read from a stream (unbuffered).
|
---|
[2595dab] | 422 | *
|
---|
| 423 | * @param buf Destination buffer.
|
---|
| 424 | * @param size Size of each record.
|
---|
| 425 | * @param nmemb Number of records to read.
|
---|
| 426 | * @param stream Pointer to the stream.
|
---|
[6afc9d7] | 427 | *
|
---|
| 428 | * @return Number of elements successfully read. On error this is less than
|
---|
| 429 | * nmemb, stream error indicator is set and errno is set.
|
---|
[4e2cf8b] | 430 | */
|
---|
[facebd56] | 431 | static size_t _fread(void *buf, size_t size, size_t nmemb, FILE *stream)
|
---|
[4e2cf8b] | 432 | {
|
---|
[002252a] | 433 | if (size == 0 || nmemb == 0)
|
---|
| 434 | return 0;
|
---|
| 435 |
|
---|
[ce04ea44] | 436 | ssize_t rd = vfs_read(stream->fd, &stream->pos, buf, size * nmemb);
|
---|
[58898d1d] | 437 | if (rd < 0) {
|
---|
[ce04ea44] | 438 | errno = rd;
|
---|
[58898d1d] | 439 | stream->error = true;
|
---|
| 440 | rd = 0;
|
---|
| 441 | } else if (rd == 0) {
|
---|
| 442 | stream->eof = true;
|
---|
[2595dab] | 443 | }
|
---|
[4e2cf8b] | 444 |
|
---|
[58898d1d] | 445 | return (rd / size);
|
---|
[2595dab] | 446 | }
|
---|
[55cff86] | 447 |
|
---|
[facebd56] | 448 | /** Write to a stream (unbuffered).
|
---|
| 449 | *
|
---|
| 450 | * @param buf Source buffer.
|
---|
| 451 | * @param size Size of each record.
|
---|
| 452 | * @param nmemb Number of records to write.
|
---|
| 453 | * @param stream Pointer to the stream.
|
---|
[6afc9d7] | 454 | *
|
---|
| 455 | * @return Number of elements successfully written. On error this is less than
|
---|
| 456 | * nmemb, stream error indicator is set and errno is set.
|
---|
[facebd56] | 457 | */
|
---|
[ef8bcc6] | 458 | static size_t _fwrite(const void *buf, size_t size, size_t nmemb, FILE *stream)
|
---|
[2595dab] | 459 | {
|
---|
[002252a] | 460 | if (size == 0 || nmemb == 0)
|
---|
| 461 | return 0;
|
---|
| 462 |
|
---|
[58898d1d] | 463 | ssize_t wr;
|
---|
| 464 | if (stream->kio) {
|
---|
| 465 | size_t nwritten;
|
---|
| 466 | wr = kio_write(buf, size * nmemb, &nwritten);
|
---|
| 467 | if (wr != EOK) {
|
---|
| 468 | stream->error = true;
|
---|
| 469 | wr = 0;
|
---|
[6afc9d7] | 470 | } else {
|
---|
[58898d1d] | 471 | wr = nwritten;
|
---|
[6afc9d7] | 472 | }
|
---|
[58898d1d] | 473 | } else {
|
---|
[ce04ea44] | 474 | wr = vfs_write(stream->fd, &stream->pos, buf, size * nmemb);
|
---|
[58898d1d] | 475 | if (wr < 0) {
|
---|
[ce04ea44] | 476 | errno = wr;
|
---|
[2595dab] | 477 | stream->error = true;
|
---|
[58898d1d] | 478 | wr = 0;
|
---|
[2595dab] | 479 | }
|
---|
| 480 | }
|
---|
[facebd56] | 481 |
|
---|
[58898d1d] | 482 | if (wr > 0)
|
---|
[facebd56] | 483 | stream->need_sync = true;
|
---|
[2595dab] | 484 |
|
---|
[58898d1d] | 485 | return (wr / size);
|
---|
[4e2cf8b] | 486 | }
|
---|
| 487 |
|
---|
[6afc9d7] | 488 | /** Read some data in stream buffer.
|
---|
| 489 | *
|
---|
| 490 | * On error, stream error indicator is set and errno is set.
|
---|
| 491 | */
|
---|
[facebd56] | 492 | static void _ffillbuf(FILE *stream)
|
---|
| 493 | {
|
---|
| 494 | ssize_t rc;
|
---|
| 495 |
|
---|
| 496 | stream->buf_head = stream->buf_tail = stream->buf;
|
---|
| 497 |
|
---|
[ce04ea44] | 498 | rc = vfs_read(stream->fd, &stream->pos, stream->buf, stream->buf_size);
|
---|
[facebd56] | 499 | if (rc < 0) {
|
---|
[ce04ea44] | 500 | errno = rc;
|
---|
[facebd56] | 501 | stream->error = true;
|
---|
| 502 | return;
|
---|
| 503 | }
|
---|
| 504 |
|
---|
| 505 | if (rc == 0) {
|
---|
| 506 | stream->eof = true;
|
---|
| 507 | return;
|
---|
| 508 | }
|
---|
| 509 |
|
---|
| 510 | stream->buf_head += rc;
|
---|
| 511 | stream->buf_state = _bs_read;
|
---|
| 512 | }
|
---|
| 513 |
|
---|
| 514 | /** Write out stream buffer, do not sync stream. */
|
---|
[ef8bcc6] | 515 | static void _fflushbuf(FILE *stream)
|
---|
| 516 | {
|
---|
| 517 | size_t bytes_used;
|
---|
[facebd56] | 518 |
|
---|
[bfd247f] | 519 | if ((!stream->buf) || (stream->btype == _IONBF) || (stream->error))
|
---|
[ef8bcc6] | 520 | return;
|
---|
[facebd56] | 521 |
|
---|
| 522 | bytes_used = stream->buf_head - stream->buf_tail;
|
---|
| 523 |
|
---|
| 524 | /* If buffer has prefetched read data, we need to seek back. */
|
---|
[58898d1d] | 525 | if (bytes_used > 0 && stream->buf_state == _bs_read)
|
---|
| 526 | stream->pos -= bytes_used;
|
---|
[facebd56] | 527 |
|
---|
| 528 | /* If buffer has unwritten data, we need to write them out. */
|
---|
[6afc9d7] | 529 | if (bytes_used > 0 && stream->buf_state == _bs_write) {
|
---|
[facebd56] | 530 | (void) _fwrite(stream->buf_tail, 1, bytes_used, stream);
|
---|
[6afc9d7] | 531 | /* On error stream error indicator and errno are set by _fwrite */
|
---|
| 532 | if (stream->error)
|
---|
| 533 | return;
|
---|
| 534 | }
|
---|
[facebd56] | 535 |
|
---|
[ef8bcc6] | 536 | stream->buf_head = stream->buf;
|
---|
[facebd56] | 537 | stream->buf_tail = stream->buf;
|
---|
| 538 | stream->buf_state = _bs_empty;
|
---|
[ef8bcc6] | 539 | }
|
---|
| 540 |
|
---|
[facebd56] | 541 | /** Read from a stream.
|
---|
| 542 | *
|
---|
| 543 | * @param dest Destination buffer.
|
---|
| 544 | * @param size Size of each record.
|
---|
| 545 | * @param nmemb Number of records to read.
|
---|
| 546 | * @param stream Pointer to the stream.
|
---|
| 547 | *
|
---|
| 548 | */
|
---|
| 549 | size_t fread(void *dest, size_t size, size_t nmemb, FILE *stream)
|
---|
| 550 | {
|
---|
| 551 | uint8_t *dp;
|
---|
| 552 | size_t bytes_left;
|
---|
| 553 | size_t now;
|
---|
| 554 | size_t data_avail;
|
---|
| 555 | size_t total_read;
|
---|
| 556 | size_t i;
|
---|
| 557 |
|
---|
| 558 | if (size == 0 || nmemb == 0)
|
---|
| 559 | return 0;
|
---|
| 560 |
|
---|
[bd5414e] | 561 | bytes_left = size * nmemb;
|
---|
| 562 | total_read = 0;
|
---|
| 563 | dp = (uint8_t *) dest;
|
---|
| 564 |
|
---|
| 565 | /* Bytes from ungetc() buffer */
|
---|
| 566 | while (stream->ungetc_chars > 0 && bytes_left > 0) {
|
---|
| 567 | *dp++ = stream->ungetc_buf[--stream->ungetc_chars];
|
---|
| 568 | ++total_read;
|
---|
[a955fcc] | 569 | --bytes_left;
|
---|
[bd5414e] | 570 | }
|
---|
| 571 |
|
---|
[facebd56] | 572 | /* If not buffered stream, read in directly. */
|
---|
| 573 | if (stream->btype == _IONBF) {
|
---|
[bd5414e] | 574 | total_read += _fread(dest, 1, bytes_left, stream);
|
---|
| 575 | return total_read / size;
|
---|
[facebd56] | 576 | }
|
---|
| 577 |
|
---|
| 578 | /* Make sure no data is pending write. */
|
---|
| 579 | if (stream->buf_state == _bs_write)
|
---|
| 580 | _fflushbuf(stream);
|
---|
| 581 |
|
---|
| 582 | /* Perform lazy allocation of stream buffer. */
|
---|
| 583 | if (stream->buf == NULL) {
|
---|
| 584 | if (_fallocbuf(stream) != 0)
|
---|
| 585 | return 0; /* Errno set by _fallocbuf(). */
|
---|
| 586 | }
|
---|
| 587 |
|
---|
| 588 | while ((!stream->error) && (!stream->eof) && (bytes_left > 0)) {
|
---|
| 589 | if (stream->buf_head == stream->buf_tail)
|
---|
| 590 | _ffillbuf(stream);
|
---|
| 591 |
|
---|
[6afc9d7] | 592 | if (stream->error || stream->eof) {
|
---|
| 593 | /* On error errno was set by _ffillbuf() */
|
---|
[facebd56] | 594 | break;
|
---|
[6afc9d7] | 595 | }
|
---|
[facebd56] | 596 |
|
---|
| 597 | data_avail = stream->buf_head - stream->buf_tail;
|
---|
| 598 |
|
---|
| 599 | if (bytes_left > data_avail)
|
---|
| 600 | now = data_avail;
|
---|
| 601 | else
|
---|
| 602 | now = bytes_left;
|
---|
| 603 |
|
---|
| 604 | for (i = 0; i < now; i++) {
|
---|
| 605 | dp[i] = stream->buf_tail[i];
|
---|
| 606 | }
|
---|
| 607 |
|
---|
| 608 | dp += now;
|
---|
| 609 | stream->buf_tail += now;
|
---|
| 610 | bytes_left -= now;
|
---|
| 611 | total_read += now;
|
---|
| 612 | }
|
---|
| 613 |
|
---|
| 614 | return (total_read / size);
|
---|
| 615 | }
|
---|
| 616 |
|
---|
| 617 |
|
---|
[ef8bcc6] | 618 | /** Write to a stream.
|
---|
| 619 | *
|
---|
| 620 | * @param buf Source buffer.
|
---|
| 621 | * @param size Size of each record.
|
---|
| 622 | * @param nmemb Number of records to write.
|
---|
| 623 | * @param stream Pointer to the stream.
|
---|
| 624 | *
|
---|
| 625 | */
|
---|
| 626 | size_t fwrite(const void *buf, size_t size, size_t nmemb, FILE *stream)
|
---|
| 627 | {
|
---|
| 628 | uint8_t *data;
|
---|
| 629 | size_t bytes_left;
|
---|
| 630 | size_t now;
|
---|
| 631 | size_t buf_free;
|
---|
| 632 | size_t total_written;
|
---|
| 633 | size_t i;
|
---|
| 634 | uint8_t b;
|
---|
| 635 | bool need_flush;
|
---|
[002252a] | 636 |
|
---|
| 637 | if (size == 0 || nmemb == 0)
|
---|
| 638 | return 0;
|
---|
| 639 |
|
---|
[ef8bcc6] | 640 | /* If not buffered stream, write out directly. */
|
---|
[bfd247f] | 641 | if (stream->btype == _IONBF) {
|
---|
| 642 | now = _fwrite(buf, size, nmemb, stream);
|
---|
| 643 | fflush(stream);
|
---|
| 644 | return now;
|
---|
| 645 | }
|
---|
[facebd56] | 646 |
|
---|
| 647 | /* Make sure buffer contains no prefetched data. */
|
---|
| 648 | if (stream->buf_state == _bs_read)
|
---|
| 649 | _fflushbuf(stream);
|
---|
| 650 |
|
---|
[ef8bcc6] | 651 | /* Perform lazy allocation of stream buffer. */
|
---|
| 652 | if (stream->buf == NULL) {
|
---|
| 653 | if (_fallocbuf(stream) != 0)
|
---|
| 654 | return 0; /* Errno set by _fallocbuf(). */
|
---|
| 655 | }
|
---|
[bfd247f] | 656 |
|
---|
[ef8bcc6] | 657 | data = (uint8_t *) buf;
|
---|
| 658 | bytes_left = size * nmemb;
|
---|
| 659 | total_written = 0;
|
---|
| 660 | need_flush = false;
|
---|
[bfd247f] | 661 |
|
---|
| 662 | while ((!stream->error) && (bytes_left > 0)) {
|
---|
[ef8bcc6] | 663 | buf_free = stream->buf_size - (stream->buf_head - stream->buf);
|
---|
| 664 | if (bytes_left > buf_free)
|
---|
| 665 | now = buf_free;
|
---|
| 666 | else
|
---|
| 667 | now = bytes_left;
|
---|
[bfd247f] | 668 |
|
---|
[ef8bcc6] | 669 | for (i = 0; i < now; i++) {
|
---|
| 670 | b = data[i];
|
---|
| 671 | stream->buf_head[i] = b;
|
---|
[bfd247f] | 672 |
|
---|
| 673 | if ((b == '\n') && (stream->btype == _IOLBF))
|
---|
[ef8bcc6] | 674 | need_flush = true;
|
---|
| 675 | }
|
---|
[bfd247f] | 676 |
|
---|
[0803134] | 677 | data += now;
|
---|
[ef8bcc6] | 678 | stream->buf_head += now;
|
---|
| 679 | buf_free -= now;
|
---|
| 680 | bytes_left -= now;
|
---|
| 681 | total_written += now;
|
---|
[0803134] | 682 | stream->buf_state = _bs_write;
|
---|
[bfd247f] | 683 |
|
---|
[ef8bcc6] | 684 | if (buf_free == 0) {
|
---|
| 685 | /* Only need to drain buffer. */
|
---|
| 686 | _fflushbuf(stream);
|
---|
[6afc9d7] | 687 | if (!stream->error)
|
---|
| 688 | need_flush = false;
|
---|
[ef8bcc6] | 689 | }
|
---|
| 690 | }
|
---|
[facebd56] | 691 |
|
---|
[ef8bcc6] | 692 | if (need_flush)
|
---|
| 693 | fflush(stream);
|
---|
[bfd247f] | 694 |
|
---|
[ef8bcc6] | 695 | return (total_written / size);
|
---|
| 696 | }
|
---|
| 697 |
|
---|
[2595dab] | 698 | int fputc(wchar_t c, FILE *stream)
|
---|
[c9857c6] | 699 | {
|
---|
[56fa418] | 700 | char buf[STR_BOUNDS(1)];
|
---|
[2595dab] | 701 | size_t sz = 0;
|
---|
| 702 |
|
---|
| 703 | if (chr_encode(c, buf, &sz, STR_BOUNDS(1)) == EOK) {
|
---|
[2a5af223] | 704 | size_t wr = fwrite(buf, 1, sz, stream);
|
---|
[2595dab] | 705 |
|
---|
| 706 | if (wr < sz)
|
---|
| 707 | return EOF;
|
---|
| 708 |
|
---|
| 709 | return (int) c;
|
---|
| 710 | }
|
---|
| 711 |
|
---|
| 712 | return EOF;
|
---|
| 713 | }
|
---|
[56fa418] | 714 |
|
---|
[2595dab] | 715 | int putchar(wchar_t c)
|
---|
| 716 | {
|
---|
| 717 | return fputc(c, stdout);
|
---|
| 718 | }
|
---|
[56fa418] | 719 |
|
---|
[2595dab] | 720 | int fputs(const char *str, FILE *stream)
|
---|
| 721 | {
|
---|
[7db5cfd] | 722 | (void) fwrite(str, str_size(str), 1, stream);
|
---|
| 723 | if (ferror(stream))
|
---|
| 724 | return EOF;
|
---|
| 725 | return 0;
|
---|
[2595dab] | 726 | }
|
---|
[56fa418] | 727 |
|
---|
[2595dab] | 728 | int puts(const char *str)
|
---|
| 729 | {
|
---|
| 730 | return fputs(str, stdout);
|
---|
[c9857c6] | 731 | }
|
---|
[b27a97bb] | 732 |
|
---|
[2595dab] | 733 | int fgetc(FILE *stream)
|
---|
[b27a97bb] | 734 | {
|
---|
[2595dab] | 735 | char c;
|
---|
[bfd247f] | 736 |
|
---|
[bac82eeb] | 737 | /* This could be made faster by only flushing when needed. */
|
---|
[b8e57e8c] | 738 | if (stdout)
|
---|
| 739 | fflush(stdout);
|
---|
| 740 | if (stderr)
|
---|
| 741 | fflush(stderr);
|
---|
[bfd247f] | 742 |
|
---|
[2595dab] | 743 | if (fread(&c, sizeof(char), 1, stream) < sizeof(char))
|
---|
| 744 | return EOF;
|
---|
[b27a97bb] | 745 |
|
---|
[2595dab] | 746 | return (int) c;
|
---|
| 747 | }
|
---|
| 748 |
|
---|
[c62d2e1] | 749 | char *fgets(char *str, int size, FILE *stream)
|
---|
| 750 | {
|
---|
[a634485] | 751 | int c;
|
---|
[c62d2e1] | 752 | int idx;
|
---|
| 753 |
|
---|
| 754 | idx = 0;
|
---|
| 755 | while (idx < size - 1) {
|
---|
| 756 | c = fgetc(stream);
|
---|
| 757 | if (c == EOF)
|
---|
| 758 | break;
|
---|
| 759 |
|
---|
| 760 | str[idx++] = c;
|
---|
| 761 |
|
---|
| 762 | if (c == '\n')
|
---|
| 763 | break;
|
---|
| 764 | }
|
---|
| 765 |
|
---|
| 766 | if (ferror(stream))
|
---|
| 767 | return NULL;
|
---|
| 768 |
|
---|
| 769 | if (idx == 0)
|
---|
| 770 | return NULL;
|
---|
| 771 |
|
---|
| 772 | str[idx] = '\0';
|
---|
| 773 | return str;
|
---|
| 774 | }
|
---|
| 775 |
|
---|
[2595dab] | 776 | int getchar(void)
|
---|
| 777 | {
|
---|
| 778 | return fgetc(stdin);
|
---|
[b27a97bb] | 779 | }
|
---|
| 780 |
|
---|
[bd5414e] | 781 | int ungetc(int c, FILE *stream)
|
---|
| 782 | {
|
---|
| 783 | if (c == EOF)
|
---|
| 784 | return EOF;
|
---|
| 785 |
|
---|
| 786 | if (stream->ungetc_chars >= UNGETC_MAX)
|
---|
| 787 | return EOF;
|
---|
| 788 |
|
---|
| 789 | stream->ungetc_buf[stream->ungetc_chars++] =
|
---|
| 790 | (uint8_t)c;
|
---|
| 791 |
|
---|
| 792 | stream->eof = false;
|
---|
| 793 | return (uint8_t)c;
|
---|
| 794 | }
|
---|
| 795 |
|
---|
[ed903174] | 796 | int fseek(FILE *stream, off64_t offset, int whence)
|
---|
[d2cc7e1] | 797 | {
|
---|
[23a0368] | 798 | int rc;
|
---|
| 799 |
|
---|
[6afc9d7] | 800 | if (stream->error)
|
---|
[58898d1d] | 801 | return -1;
|
---|
[6afc9d7] | 802 |
|
---|
[facebd56] | 803 | _fflushbuf(stream);
|
---|
[6afc9d7] | 804 | if (stream->error) {
|
---|
| 805 | /* errno was set by _fflushbuf() */
|
---|
[58898d1d] | 806 | return -1;
|
---|
[6afc9d7] | 807 | }
|
---|
| 808 |
|
---|
[bd5414e] | 809 | stream->ungetc_chars = 0;
|
---|
[facebd56] | 810 |
|
---|
[58898d1d] | 811 | struct stat st;
|
---|
| 812 | switch (whence) {
|
---|
| 813 | case SEEK_SET:
|
---|
| 814 | stream->pos = offset;
|
---|
| 815 | break;
|
---|
| 816 | case SEEK_CUR:
|
---|
| 817 | stream->pos += offset;
|
---|
| 818 | break;
|
---|
| 819 | case SEEK_END:
|
---|
[23a0368] | 820 | rc = vfs_stat(stream->fd, &st);
|
---|
| 821 | if (rc != EOK) {
|
---|
| 822 | errno = rc;
|
---|
[58898d1d] | 823 | stream->error = true;
|
---|
| 824 | return -1;
|
---|
| 825 | }
|
---|
| 826 | stream->pos = st.size + offset;
|
---|
| 827 | break;
|
---|
[2595dab] | 828 | }
|
---|
[facebd56] | 829 |
|
---|
[2595dab] | 830 | stream->eof = false;
|
---|
[566f4cfb] | 831 | return 0;
|
---|
[d2cc7e1] | 832 | }
|
---|
| 833 |
|
---|
[ed903174] | 834 | off64_t ftell(FILE *stream)
|
---|
[08232ee] | 835 | {
|
---|
[6afc9d7] | 836 | if (stream->error)
|
---|
| 837 | return EOF;
|
---|
| 838 |
|
---|
[8ad496d2] | 839 | _fflushbuf(stream);
|
---|
[6afc9d7] | 840 | if (stream->error) {
|
---|
| 841 | /* errno was set by _fflushbuf() */
|
---|
| 842 | return EOF;
|
---|
| 843 | }
|
---|
| 844 |
|
---|
[58898d1d] | 845 | return stream->pos - stream->ungetc_chars;
|
---|
[08232ee] | 846 | }
|
---|
| 847 |
|
---|
[080ad7f] | 848 | void rewind(FILE *stream)
|
---|
| 849 | {
|
---|
| 850 | (void) fseek(stream, 0, SEEK_SET);
|
---|
| 851 | }
|
---|
| 852 |
|
---|
[2595dab] | 853 | int fflush(FILE *stream)
|
---|
| 854 | {
|
---|
[6afc9d7] | 855 | if (stream->error)
|
---|
| 856 | return EOF;
|
---|
| 857 |
|
---|
[ef8bcc6] | 858 | _fflushbuf(stream);
|
---|
[6afc9d7] | 859 | if (stream->error) {
|
---|
| 860 | /* errno was set by _fflushbuf() */
|
---|
| 861 | return EOF;
|
---|
| 862 | }
|
---|
[bfd247f] | 863 |
|
---|
[6fa9a99d] | 864 | if (stream->kio) {
|
---|
| 865 | kio_update();
|
---|
[6afc9d7] | 866 | return 0;
|
---|
[2595dab] | 867 | }
|
---|
| 868 |
|
---|
[79ae36dd] | 869 | if ((stream->fd >= 0) && (stream->need_sync)) {
|
---|
[a56cef9] | 870 | int rc;
|
---|
| 871 |
|
---|
[facebd56] | 872 | /**
|
---|
| 873 | * Better than syncing always, but probably still not the
|
---|
| 874 | * right thing to do.
|
---|
| 875 | */
|
---|
| 876 | stream->need_sync = false;
|
---|
[a56cef9] | 877 | rc = vfs_sync(stream->fd);
|
---|
| 878 | if (rc != EOK) {
|
---|
| 879 | errno = rc;
|
---|
[6afc9d7] | 880 | return EOF;
|
---|
| 881 | }
|
---|
| 882 |
|
---|
| 883 | return 0;
|
---|
[facebd56] | 884 | }
|
---|
[2595dab] | 885 |
|
---|
[6afc9d7] | 886 | return 0;
|
---|
[2595dab] | 887 | }
|
---|
| 888 |
|
---|
| 889 | int feof(FILE *stream)
|
---|
| 890 | {
|
---|
| 891 | return stream->eof;
|
---|
| 892 | }
|
---|
| 893 |
|
---|
| 894 | int ferror(FILE *stream)
|
---|
| 895 | {
|
---|
| 896 | return stream->error;
|
---|
| 897 | }
|
---|
| 898 |
|
---|
[c77a64f] | 899 | void clearerr(FILE *stream)
|
---|
| 900 | {
|
---|
| 901 | stream->eof = false;
|
---|
| 902 | stream->error = false;
|
---|
| 903 | }
|
---|
| 904 |
|
---|
[3629481] | 905 | int fileno(FILE *stream)
|
---|
| 906 | {
|
---|
[6fa9a99d] | 907 | if (stream->kio) {
|
---|
[3629481] | 908 | errno = EBADF;
|
---|
[6afc9d7] | 909 | return EOF;
|
---|
[3629481] | 910 | }
|
---|
| 911 |
|
---|
| 912 | return stream->fd;
|
---|
| 913 | }
|
---|
| 914 |
|
---|
[6afc9d7] | 915 | async_sess_t *vfs_fsession(FILE *stream, iface_t iface)
|
---|
[2595dab] | 916 | {
|
---|
| 917 | if (stream->fd >= 0) {
|
---|
[79ae36dd] | 918 | if (stream->sess == NULL)
|
---|
[6afc9d7] | 919 | stream->sess = vfs_fd_session(stream->fd, iface);
|
---|
[2595dab] | 920 |
|
---|
[79ae36dd] | 921 | return stream->sess;
|
---|
[2595dab] | 922 | }
|
---|
| 923 |
|
---|
[79ae36dd] | 924 | return NULL;
|
---|
[2595dab] | 925 | }
|
---|
| 926 |
|
---|
[6afc9d7] | 927 | int vfs_fhandle(FILE *stream, int *handle)
|
---|
[2595dab] | 928 | {
|
---|
[7171760] | 929 | if (stream->fd >= 0) {
|
---|
| 930 | *handle = stream->fd;
|
---|
| 931 | return EOK;
|
---|
| 932 | }
|
---|
[a68f737] | 933 |
|
---|
| 934 | return ENOENT;
|
---|
[2595dab] | 935 | }
|
---|
| 936 |
|
---|
[fadd381] | 937 | /** @}
|
---|
[b2951e2] | 938 | */
|
---|