~daniel-mehrmann/e2fsprogs/master

« back to all changes in this revision

Viewing changes to util/subst.c

  • Committer: Daniel Mehrmann
  • Date: 2014-12-16 09:16:59 UTC
  • mfrom: (1.2.25)
  • Revision ID: daniel.mehrmann@gmx.de-20141216091659-ymhbl4ualba43vuc
Tags: 1.43-SN-2014-12-16-0ubuntu1
* Merge in snapshot from the maint branch 

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
#ifdef HAVE_CONFIG_H
9
9
#include "config.h"
 
10
#else
 
11
#define HAVE_SYS_TIME_H
10
12
#endif
11
13
#include <stdio.h>
12
14
#include <errno.h>
22
24
#include <fcntl.h>
23
25
#include <time.h>
24
26
#include <utime.h>
 
27
#ifdef HAVE_SYS_TIME_H
 
28
#include <sys/time.h>
 
29
#endif
25
30
 
26
31
#ifdef HAVE_GETOPT_H
27
32
#include <getopt.h>
291
296
        return retval;
292
297
}
293
298
 
 
299
void set_utimes(const char *filename, int fd, const struct timeval times[2])
 
300
{
 
301
#ifdef HAVE_FUTIMES
 
302
        if (futimes(fd, times) < 0)
 
303
                perror("futimes");
 
304
#elif HAVE_UTIMES
 
305
        if (utimes(filename, times) < 0)
 
306
                perror("utimes");
 
307
#else
 
308
        struct utimbuf ut;
 
309
 
 
310
        ut.actime = times[0].tv_sec;
 
311
        ut.modtime = times[1].tv_sec;
 
312
        if (utime(filename, &ut) < 0)
 
313
                perror("utime");
 
314
#endif
 
315
}
294
316
 
295
317
 
296
318
int main(int argc, char **argv)
405
427
                                        tv[0] = tv[1];
406
428
                                else if (verbose)
407
429
                                        printf("Using original atime\n");
408
 
#ifdef HAVE_FUTIMES
409
 
                                if (futimes(fileno(old), tv) < 0)
410
 
                                        perror("futimes");
411
 
#else
412
 
                                if (utimes(outfn, tv) < 0)
413
 
                                        perror("utimes");
414
 
#endif
 
430
                                set_utimes(outfn, fileno(old), tv);
415
431
                        }
416
432
                        fclose(out);
417
433
                        if (unlink(newfn) < 0)
431
447
        }
432
448
        if (old)
433
449
                fclose(old);
 
450
        if (newfn)
 
451
                free(newfn);
434
452
        return (0);
435
453
}
436
454