/[mailutils]/mailutils/mailbox/mutil.c
ViewVC logotype

Diff of /mailutils/mailbox/mutil.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.24 by gray, Tue Feb 19 17:00:46 2002 UTC revision 1.25 by gray, Wed Feb 27 11:57:38 2002 UTC
# Line 265  mu_get_homedir (void) Line 265  mu_get_homedir (void)
265    return homedir;    return homedir;
266  }  }
267    
268    char *
269    mu_getcwd ()
270    {
271      char *ret;
272      unsigned path_max;
273      char buf[128];
274    
275      errno = 0;
276      ret = getcwd (buf, sizeof (buf));
277      if (ret != NULL)
278        return strdup (buf);
279    
280      if (errno != ERANGE)
281        return NULL;
282    
283      path_max = 128;
284      path_max += 2;                /* The getcwd docs say to do this. */
285    
286      for (;;)
287        {
288          char *cwd = (char *) malloc (path_max);
289    
290          errno = 0;
291          ret = getcwd (cwd, path_max);
292          if (ret != NULL)
293            return ret;
294          if (errno != ERANGE)
295            {
296              int save_errno = errno;
297              free (cwd);
298              errno = save_errno;
299              return NULL;
300            }
301    
302          free (cwd);
303    
304          path_max += path_max / 16;
305          path_max += 32;
306        }
307      /* oops?  */
308      return NULL;
309    }
310    
311    char *
312    mu_get_full_path (const char *file)
313    {
314      char *p = NULL;
315    
316      if (!file)
317        p = mu_getcwd ();
318      else if (*file != '/')
319        {
320          char *cwd = mu_getcwd ();
321          if (cwd)
322            {
323              p = calloc (strlen (cwd) + 1 + strlen (file) + 1, 1);
324              if (p)
325                sprintf (p, "%s/%s", cwd, file);
326              free (cwd);
327            }
328        }
329    
330      if (!p)
331        p = strdup (file);
332      return p;
333    }
334    
335  /* NOTE: Allocates Memory.  */  /* NOTE: Allocates Memory.  */
336  /* Expand: ~ --> /home/user and to ~guest --> /home/guest.  */  /* Expand: ~ --> /home/user and to ~guest --> /home/guest.  */
337  char *  char *

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26