~ubuntu-dev/ubuntu/lucid/mutt/lucid-201002110857

« back to all changes in this revision

Viewing changes to lib.c

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2009-06-07 17:30:03 UTC
  • mto: (16.2.1 experimental) (2.3.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20090607173003-rg37ui3h2bbv7wl0
Tags: upstream-1.5.19
ImportĀ upstreamĀ versionĀ 1.5.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
3
 
 * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
 
2
 * Copyright (C) 1996-2000,2007 Michael R. Elkins <me@mutt.org>
 
3
 * Copyright (C) 1999-2004,2006-7 Thomas Roessler <roessler@does-not-exist.org>
4
4
 * 
5
5
 *     This program is free software; you can redistribute it
6
6
 *     and/or modify it under the terms of the GNU General Public
41
41
#include <sys/stat.h>
42
42
#include <fcntl.h>
43
43
#include <pwd.h>
 
44
#include <sys/types.h>
 
45
#include <dirent.h>
44
46
 
45
47
#ifdef HAVE_SYSEXITS_H
46
48
#include <sysexits.h>
209
211
  return r;
210
212
}
211
213
 
 
214
int safe_fsync_close (FILE **f)
 
215
{
 
216
  int r = 0;
 
217
 
 
218
  if (*f)
 
219
  {
 
220
    if (fflush (*f) || fsync (fileno (*f)))
 
221
    {
 
222
      r = -1;
 
223
      fclose (*f);
 
224
    }
 
225
    else
 
226
      r = fclose(*f);
 
227
    *f = NULL;
 
228
  }
 
229
 
 
230
  return r;
 
231
}
 
232
 
212
233
char *safe_strdup (const char *s)
213
234
{
214
235
  char *p;
522
543
 
523
544
/* Create a temporary directory next to a file name */
524
545
 
525
 
int mutt_mkwrapdir (const char *path, char *newfile, size_t nflen, 
 
546
static int mutt_mkwrapdir (const char *path, char *newfile, size_t nflen, 
526
547
                    char *newdir, size_t ndlen)
527
548
{
528
549
  const char *basename;
557
578
  return 0;  
558
579
}
559
580
 
560
 
int mutt_put_file_in_place (const char *path, const char *safe_file, const char *safe_dir)
 
581
/* remove a directory and everything under it */
 
582
int mutt_rmtree (const char* path)
 
583
{
 
584
  DIR* dirp;
 
585
  struct dirent* de;
 
586
  char cur[_POSIX_PATH_MAX];
 
587
  struct stat statbuf;
 
588
  int rc = 0;
 
589
 
 
590
  if (!(dirp = opendir (path)))
 
591
  {
 
592
    dprint (1, (debugfile, "mutt_rmtree: error opening directory %s\n", path));
 
593
    return -1;
 
594
  }
 
595
  while ((de = readdir (dirp)))
 
596
  {
 
597
    if (!strcmp (".", de->d_name) || !strcmp ("..", de->d_name))
 
598
      continue;
 
599
 
 
600
    snprintf (cur, sizeof (cur), "%s/%s", path, de->d_name);
 
601
    /* XXX make nonrecursive version */
 
602
 
 
603
    if (stat(cur, &statbuf) == -1)
 
604
    {
 
605
      rc = 1;
 
606
      continue;
 
607
    }
 
608
 
 
609
    if (S_ISDIR (statbuf.st_mode))
 
610
      rc |= mutt_rmtree (cur);
 
611
    else
 
612
      rc |= unlink (cur);
 
613
  }
 
614
  closedir (dirp);
 
615
 
 
616
  rc |= rmdir (path);
 
617
 
 
618
  return rc;
 
619
}
 
620
 
 
621
static int mutt_put_file_in_place (const char *path, const char *safe_file, const char *safe_dir)
561
622
{
562
623
  int rv;
563
624