~ubuntu-branches/ubuntu/utopic/gettext/utopic

« back to all changes in this revision

Viewing changes to gettext-tools/gnulib-lib/tmpdir.c

  • Committer: Colin Watson
  • Date: 2010-08-01 21:36:08 UTC
  • mfrom: (2.1.10 sid)
  • Revision ID: cjwatson@canonical.com-20100801213608-yy7vkm8lpatep3ci
merge from Debian 0.18.1.1-1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 1999, 2001-2002, 2006 Free Software Foundation, Inc.
 
1
/* Copyright (C) 1999, 2001-2002, 2006, 2009-2010 Free Software Foundation,
 
2
   Inc.
2
3
   This file is part of the GNU C Library.
3
4
 
4
5
   This program is free software: you can redistribute it and/or modify
76
77
   enough space in TMPL. */
77
78
int
78
79
path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
79
 
             bool try_tmpdir)
 
80
             bool try_tmpdir)
80
81
{
81
82
  const char *d;
82
83
  size_t dlen, plen;
90
91
    {
91
92
      plen = strlen (pfx);
92
93
      if (plen > 5)
93
 
        plen = 5;
 
94
        plen = 5;
94
95
    }
95
96
 
96
97
  if (try_tmpdir)
97
98
    {
98
99
      d = __secure_getenv ("TMPDIR");
99
100
      if (d != NULL && direxists (d))
100
 
        dir = d;
 
101
        dir = d;
101
102
      else if (dir != NULL && direxists (dir))
102
 
        /* nothing */ ;
 
103
        /* nothing */ ;
103
104
      else
104
 
        dir = NULL;
 
105
        dir = NULL;
105
106
    }
106
107
  if (dir == NULL)
107
108
    {
108
109
      if (direxists (P_tmpdir))
109
 
        dir = P_tmpdir;
 
110
        dir = P_tmpdir;
110
111
      else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp"))
111
 
        dir = "/tmp";
 
112
        dir = "/tmp";
112
113
      else
113
 
        {
114
 
          __set_errno (ENOENT);
115
 
          return -1;
116
 
        }
 
114
        {
 
115
          __set_errno (ENOENT);
 
116
          return -1;
 
117
        }
117
118
    }
118
119
 
119
120
  dlen = strlen (dir);
120
121
  while (dlen >= 1 && ISSLASH (dir[dlen - 1]))
121
 
    dlen--;                     /* remove trailing slashes */
 
122
    dlen--;                     /* remove trailing slashes */
122
123
 
123
124
  /* check we have room for "${dir}/${pfx}XXXXXX\0" */
124
125
  if (tmpl_len < dlen + 1 + plen + 6 + 1)