Debian Codegraph @

android/app/jni/extern/macports-legacy-support/src/dprintf.c

raw
1 /*
2 * Copyright (c) 2021, Evan Miller <[email protected]>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 // MP support header
18 #include "MacportsLegacySupport.h"
19 #if __MP_LEGACY_SUPPORT_DPRINTF__
20
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <sys/errno.h>
24
25 int dprintf(int fildes, const char * __restrict format, ...) {
26 FILE *stream = fdopen(fildes, "w");
27 if (stream == NULL) {
28 errno = EBADF;
29 return -1;
30 }
31 va_list ap;
32 va_start(ap, format);
33 int result = vfprintf(stream, format, ap);
34 va_end(ap);
35 fclose(stream);
36 return result;
37 }
38
39 #endif /* __MP_LEGACY_SUPPORT_DPRINTF__ */