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