File: test_tmpfile_s.c

package info (click to toggle)
safeclib 3.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,832 kB
  • sloc: ansic: 52,639; makefile: 1,271; perl: 528; sh: 518
file content (60 lines) | stat: -rw-r--r-- 1,351 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*------------------------------------------------------------------
 * test_tmpfile_s
 * File 'io/tmpfile_s.c'
 * Lines executed:58.82% of 17
 *
 *------------------------------------------------------------------
 */

#include "test_private.h"
#include "safe_lib.h"

#ifdef HAVE_TMPFILE_S
#define HAVE_NATIVE 1
#else
#define HAVE_NATIVE 0
#endif
#include "test_msvcrt.h"
int test_tmpfile_s(void);

int test_tmpfile_s(void) {
    errno_t rc;
    int errs = 0;
    FILE *tmp;

    /*--------------------------------------------------*/

    print_msvcrt(use_msvcrt);

    rc = tmpfile_s(NULL);
    init_msvcrt(rc == ESNULLP, &use_msvcrt);
#ifdef HAVE_TMPFILE_S
    ERR_MSVC(ESNULLP, EINVAL);
#else
    ERR_MSVC(ESNULLP, EACCES);
#endif

    /*--------------------------------------------------*/

    rc = tmpfile_s(&tmp);
    if (!(rc == 0 ||
#if !defined(HAVE_TMPFILE_S) && defined(_WIN32)
          // old mingw
          rc == EACCES ||
#endif
          rc == ESLEMAX))
    {
        debug_printf("%s %u   Error rc=%d \n", __FUNCTION__, __LINE__, rc);
        errs++;
    }

    /*--------------------------------------------------*/

    return (errs);
}

#ifndef __KERNEL__
/* simple hack to get this to work for both userspace and Linux kernel,
   until a better solution can be created. */
int main(void) { return (test_tmpfile_s()); }
#endif