1 #include "mtcp_internal.h"
2
3 /**
4 * This function behaves exactly like mtcp_sys_open(), except that you are
5 * guaranteed to receive a file descriptor that is not one of the standard 3.
6 * This is useful if, for instance, you have no fd 0, receive one through
7 * open(), dup2 it to stdin, and close the original (therefore closing stdin).
8 *
9 * @param filename the file to open
10 * @param flags the flags that indicate how to open it
11 * @param mode if O_CREAT is in flags and the file gets created, mode indicates
12 * the permissions
13 *
14 * @return a file descriptor to filename, opened according to flags and mode,
15 * that is guaranteed to not be one of the standard 3
16 */
17 int mtcp_safe_open(char const *filename, int flags, mode_t mode)
18 {
19 int fds[3];
20 int i, j, fd;
21
|
At conditional (1): "i < 4": Taking true branch.
|
|
At conditional (7): "i < 4": Taking true branch.
|
|
At conditional (13): "i < 4": Taking true branch.
|
22 for(i = 0; i < 4; i++)
23 {
|
At conditional (2): "(unsigned long)resultvar >= 18446744073709547521UL": Taking false branch.
|
|
At conditional (3): "(unsigned long)resultvar >= 18446744073709547521UL": Taking false branch.
|
|
At conditional (8): "(unsigned long)resultvar >= 18446744073709547521UL": Taking false branch.
|
|
At conditional (9): "(unsigned long)resultvar >= 18446744073709547521UL": Taking false branch.
|
|
At conditional (14): "(unsigned long)resultvar >= 18446744073709547521UL": Taking false branch.
|
|
At conditional (15): "(unsigned long)resultvar >= 18446744073709547521UL": Taking false branch.
|
24 fd = mtcp_sys_open(filename, flags, mode);
25
|
At conditional (4): "fd != 0": Taking true branch.
|
|
At conditional (5): "fd != 1": Taking true branch.
|
|
At conditional (6): "fd != 2": Taking false branch.
|
|
At conditional (10): "fd != 0": Taking true branch.
|
|
At conditional (11): "fd != 1": Taking true branch.
|
|
At conditional (12): "fd != 2": Taking false branch.
|
|
At conditional (16): "fd != 0": Taking true branch.
|
|
At conditional (17): "fd != 1": Taking true branch.
|
|
At conditional (18): "fd != 2": Taking false branch.
|
26 if((fd != STDIN_FILENO) &&
27 (fd != STDOUT_FILENO) &&
28 (fd != STDERR_FILENO))
29 break;
30
|
Event overrun-local: |
Overrunning static array "fds", with 3 elements, at position 3 with index variable "i". |
31 fds[i] = fd;
32 }
33
34 for(j = 0; j < i; j++)
35 mtcp_sys_close(fds[j]);
36
37 return fd;
38 }