• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "test.h"
2 #include "safe_macros.h"
3 
4 char *TCID = "test_safe_macros";
5 int TST_TOTAL = 1;
6 
7 int fd = -1;
8 
cleanup(void)9 void cleanup(void)
10 {
11 	SAFE_CLOSE(NULL, fd);
12 	SAFE_UNLINK(NULL, __FILE__ "~");
13 	tst_resm(TINFO, "got here");
14 }
15 
main(int argc LTP_ATTRIBUTE_UNUSED,char ** argv)16 int main(int argc LTP_ATTRIBUTE_UNUSED, char **argv)
17 {
18 	char buf[10];
19 	int fds[2];
20 
21 	buf[9] = '\0';
22 
23 	if (system("cp " __FILE__ " " __FILE__ "~")) {
24 		fprintf(stderr, "error: could not cp file\n");
25 		return 1;
26 	}
27 	printf("%s\n", SAFE_BASENAME(NULL, *argv));
28 	printf("%s\n", SAFE_DIRNAME(NULL, *argv));
29 	fd = SAFE_OPEN(cleanup, __FILE__ "~", O_RDWR);
30 	SAFE_READ(cleanup, 0, fd, buf, 9);
31 	printf("buf: %s\n", buf);
32 	SAFE_READ(cleanup, 1, fd, buf, 9);
33 	printf("buf: %s\n", buf);
34 	SAFE_WRITE(cleanup, 0, -1, buf, 9);
35 	SAFE_WRITE(NULL, 0, fd, buf, 9);
36 	SAFE_WRITE(NULL, 1, fd, buf, 9);
37 	SAFE_PIPE(NULL, fds);
38 
39 	return 0;
40 }
41