skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

openwritenclose_suffix6.c (580B)


      1 /* ISC license. */
      2 
      3 #include <string.h>
      4 #include <stdio.h>
      5 
      6 #include <skalibs/posixplz.h>
      7 #include <skalibs/djbunix.h>
      8 
      9 int openwritenclose_suffix6 (char const *fn, char const *s, size_t n, devino *devino, unsigned int options, char const *suffix)
     10 {
     11   size_t len = strlen(fn) ;
     12   size_t suffixlen = strlen(suffix) ;
     13   char tmp[len + suffixlen + 1] ;
     14   memcpy(tmp, fn, len) ;
     15   memcpy(tmp + len, suffix, suffixlen + 1) ;
     16   if (!openwritenclose_unsafe5(tmp, s, n, devino, options)) return 0 ;	
     17   if (rename(tmp, fn) < 0)
     18   {
     19     unlink_void(tmp) ;
     20     return 0 ;
     21   }
     22   return 1 ;
     23 }