@@ -2496,90 +2496,42 @@ void wrapper_longjmp(uint8_t* mem, uint32_t addr, int status) {
24962496 assert (0 && "longjmp not implemented" );
24972497}
24982498
2499- uint32_t wrapper_tempnam (uint8_t * mem , uint32_t dir_addr , uint32_t pfx_addr ) {
2500- char template [1024 ];
2501- int fd ;
2502- size_t len ;
2503- uint32_t ret_addr ;
2504- const char * tmpdir ;
2505-
2506- tmpdir = getenv ("TMPDIR" );
2507-
2508- if (tmpdir != NULL ) {
2509- strcpy (template , tmpdir );
2510- } else if (dir_addr != 0 ) {
2511- STRING (dir )
2512-
2513- if (dir [0 ] != '\0 ') {
2514- strcpy (template , dir );
2515- } else {
2516- strcpy (template , "/tmp" );
2517- }
2518- } else {
2519- strcpy (template , "/tmp" );
2520- }
2521-
2522- strcat (template , "/" );
2523-
2524- if (pfx_addr != 0 ) {
2525- STRING (pfx )
2526-
2527- if (strlen (pfx ) <= 5 ) {
2528- strcat (template , pfx );
2529- }
2530- }
2531-
2532- strcat (template , "_ido_tempnam_XXXXXX" );
2533-
2534- fd = mkstemp (template );
2535- if (fd == -1 ) {
2499+ uint32_t wrapper_tempnam (uint8_t * mem , uint32_t dir_addr , uint32_t pfx_addr ) {
2500+ STRING (dir )
2501+ STRING (pfx )
2502+ char * ret = tempnam (dir , pfx );
2503+ char * ret_saved = ret ;
2504+ if (ret == NULL) {
25362505 MEM_U32 (ERRNO_ADDR ) = errno ;
25372506 return 0 ;
2538- } else {
2539- // close the file descriptor to mimic tempnam's behaviour
2540- close (fd );
25412507 }
2542-
2543- len = strlen (template ) + 1 ;
2544- ret_addr = wrapper_malloc (mem , len );
2545-
2546- strcpy1 (mem , ret_addr , template );
2508+ size_t len = strlen (ret ) + 1 ;
2509+ uint32_t ret_addr = wrapper_malloc (mem , len );
2510+ uint32_t pos = ret_addr ;
2511+ while (len -- ) {
2512+ MEM_S8 (pos ) = * ret ;
2513+ ++ pos ;
2514+ ++ ret ;
2515+ }
2516+ free (ret_saved );
25472517 return ret_addr ;
25482518}
25492519
2550- uint32_t wrapper_tmpnam (uint8_t * mem , uint32_t str_addr ) {
2551- char template [1024 ];
2552- int fd ;
2553-
2520+ uint32_t wrapper_tmpnam (uint8_t * mem , uint32_t str_addr ) {
2521+ char buf [1024 ];
25542522 assert (str_addr != 0 && "s NULL not implemented for tmpnam" );
2555-
2556- strcpy (template , "/tmp/ido_tmpnam_XXXXXX" );
2557-
2558- fd = mkstemp (template );
2559- if (fd == -1 ) {
2523+ char * ret = tmpnam (buf );
2524+ if (ret == NULL ) {
25602525 return 0 ;
25612526 } else {
2562- // close the file descriptor to mimic tmpnam's behaviour
2563- close ( fd ) ;
2527+ strcpy1 ( mem , str_addr , ret );
2528+ return str_addr ;
25642529 }
2565-
2566- strcpy1 (mem , str_addr , template );
2567- return str_addr ;
25682530}
25692531
2570- uint32_t wrapper_mktemp (uint8_t * mem , uint32_t template_addr ) {
2571- int fd ;
2532+ uint32_t wrapper_mktemp (uint8_t * mem , uint32_t template_addr ) {
25722533 STRING (template )
2573-
2574- fd = mkstemp (template );
2575- if (fd == -1 ) {
2576- MEM_U32 (ERRNO_ADDR ) = errno ;
2577- template [0 ] = '\0' ;
2578- } else {
2579- // close the file descriptor to mimic mktemp's behaviour
2580- close (fd );
2581- }
2582-
2534+ mktemp (template );
25832535 strcpy1 (mem , template_addr , template );
25842536 return template_addr ;
25852537}
0 commit comments