2 // { dg-options "-O2" }
6 extern "C" int error_open_missing_mode (void)
7 __attribute__((__error__ ("open with O_CREAT needs 3 arguments, only 2 were given")));
8 extern "C" int warn_open_too_many_arguments (void)
9 __attribute__((__warning__ ("open called with more than 3 arguments")));
10 extern "C" void abort (void);
14 __attribute__((noinline)) int
15 myopen2 (const char *path, int oflag)
17 if (expected_char++ != path[0] || path[1] != '\0')
28 // In real __open_2 this would terminate the program:
29 // open with O_CREAT without third argument.
37 __attribute__((noinline)) int
38 myopenva (const char *path, int oflag, ...)
42 if ((oflag & 0x40) != 0)
45 mode = va_arg (ap, int);
48 if (expected_char++ != path[0] || path[1] != '\0')
53 if (oflag != 0x43 || mode != 0644)
65 if (oflag != 0x43 || mode != 0600)
78 extern inline __attribute__((always_inline, gnu_inline)) int
79 myopen (const char *path, int oflag, ...)
81 if (__builtin_va_arg_pack_len () > 1)
82 warn_open_too_many_arguments ();
84 if (__builtin_constant_p (oflag))
86 if ((oflag & 0x40) != 0 && __builtin_va_arg_pack_len () < 1)
88 error_open_missing_mode ();
89 return myopen2 (path, oflag);
91 return myopenva (path, oflag, __builtin_va_arg_pack ());
94 if (__builtin_va_arg_pack_len () < 1)
95 return myopen2 (path, oflag);
97 return myopenva (path, oflag, __builtin_va_arg_pack ());
106 if (myopen ("a", 0x43, 0644))
108 if (myopen ("b", 0x3, 0755))
110 if (myopen ("c", 0x2))
112 if (myopen ("d", l0 + 0x43, 0600))
114 if (myopen ("e", l0 + 0x3, 0700))
116 if (myopen ("f", l0 + 0x2))
118 // Invalid use of myopen, but only detectable at runtime.
119 if (myopen ("g", l0 + 0x43) != -6)