gnunet-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [GNUnet-developers] expand filename diff


From: Christian Grothoff
Subject: Re: [GNUnet-developers] expand filename diff
Date: Thu, 11 Jul 2002 11:14:29 -0500
User-agent: KMail/1.4.1

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 10 July 2002 03:26 pm, Blake Matheny wrote:
> Hi Glen,
> the reason that we are not using wordexp (and we were) is that it's a glibc
> ism. Solaris, bsd, etc do not have that function.
>
> -Blake

In fact, we used wordexp before we made GNUnet work under BSD. Still, the 
spaces in filenames issue should be resolved. 

Christian

> Whatchu talkin' 'bout, Willis?
>
> > This diff changes expandFileName to use the wordexp function which
> > handles environment variable substitution and ~ expansion.
> >
> > I also made it handle spaces in the filename, i think ive done it the
> > hard way as i could work out how to use the WRDE_APPEND flag with
> > wordexp.
> >
> > Im not sure if having spaces in filenames should be supported, or how
> > portable the wordexp function is.
> >
> >
> > Glenn
> > --- ./GNUnet/src/util/storage.c     Wed Jul 10 17:49:37 2002
> > +++ ./GNUnet.orig/src/util/storage.c        Wed Jul 10 17:54:30 2002
> > @@ -40,7 +40,6 @@
> >  #include <grp.h>
> >  #include <dirent.h>
> >  #include <errno.h>
> > -#include <wordexp.h>
> >
> >  static int atoo(char *s) {
> >    int n = 0;
> > @@ -91,34 +90,46 @@
> >   * @returns the full file name, expanded with wordexp,
> >   *          NULL is returned on error
> >   **/
> > -FileName expandFileName(FileName filename)
> > -{
> > -   wordexp_t result;
> > -   char *expanded_filename;
> > -   unsigned short i;
> > -   unsigned short expanded_filename_count;
> > -
> > -   if (wordexp(filename, &result, 0)) {
> > -           /* An error occured, dont expand */
> > -           wordfree(&result);
> > -           return(filename);
> > -   }
> > -
> > -   expanded_filename_count = 1 + strlen(result.we_wordv[0]);
> > -   expanded_filename = malloc(expanded_filename_count);
> > -   strcpy(expanded_filename, result.we_wordv[0]);
> > -
> > -   /* Expand the strings specified for the arguments.  */
> > -   for (i = 1; i < result.we_wordc; i++) {
> > -           expanded_filename_count += strlen(result.we_wordv[i]) + 1;
> > -           expanded_filename = realloc(expanded_filename,
> > expanded_filename_count); -         strcat(expanded_filename, " ");
> > -           strcat(expanded_filename, result.we_wordv[i]);
> > -    }
> > -   wordfree(&result);
> > -
> > -   return(expanded_filename);
> > -}
> > +FileName expandFileName(FileName fil) {
> > +  FileName fm;
> > +  FileName fn;
> > +
> > +  if (fil == NULL)
> > +    return NULL;
> > +
> > +  if (fil[0] == '~') {
> > +    fm = getenv("HOME");
> > +    if (fm == NULL)
> > +      fm = "$HOME"; /* keep it symbolic to show error to user! */
> > +    fn = xmalloc(strlen(fm) + strlen(fil) + 1,
> > +            "expandFileName: fn");
> > +    fn[0] = 0;
> > +    strcat(fn, fm);
> > +    strcat(fn, "/");
> > +    strcat(fn, &fil[1]); /* do not copy '~' */
> > +    return fn;
> > +  }
> > +  if (fil[0] == '/') {
> > +    /* absolute path, just copy */
> > +    fn = xmalloc(strlen(fil) + 1,
> > +            "expandFileName: fn (2)");
> > +    strcpy(fn, fil);
> > +    return fn;
> > +  }
> > +  fm = getenv("PWD");
> > +  if (fm == NULL)
> > +    fm = "$PWD";
> > +  fn = xmalloc(strlen(fm) + 1 + strlen(fil) + 1,
> > +          "expandFileName: fn (3)");
> > +  fn[0] = 0;
> > +  strcat(fn, fm);
> > +  strcat(fn, "/");
> > +  strcat(fn, fil);
> > +
> > +  printf("filename is %s, was %s\n", fn, fil);
> > +  getchar();
> > +  return fn;
> > +}
> >
> >  /**
> >   * implementation of "mkdir -p"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9La7l9tNtMeXQLkIRAorkAKCIMQ/07KFjFu/Y8ofkg1CPDqSCSQCgoVS/
s242xuBIR8YDY6GgkreTf8g=
=uf5R
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]