"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "littleutils/tempname.c" between
littleutils-1.2.3.tar.lz and littleutils-1.2.4.tar.lz

About: littleutils are a collection of small and simple utilities (rename files, search for duplicate files, ...).

tempname.c  (littleutils-1.2.3.tar.lz):tempname.c  (littleutils-1.2.4.tar.lz)
/* tempname: Creates a unique temporary file (or filename) for use by shell /* tempname: Creates a unique temporary file (or filename) for use by shell
scripts. scripts.
Copyright (C) 2004-2020 by Brian Lindholm. Copyright (C) 2004-2021 by Brian Lindholm.
This file is part of the littleutils utility set. This file is part of the littleutils utility set.
The tempname utility is free software; you can redistribute it and/or The tempname utility is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as published by modify it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option) any the Free Software Foundation; either version 3, or (at your option) any
later version. later version.
The tempname utility is distributed in the hope that it will be useful, but The tempname utility is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
skipping to change at line 103 skipping to change at line 103
if (verbose) if (verbose)
fprintf (stderr, "tempname error: %s doesn't exist\n", path); fprintf (stderr, "tempname error: %s doesn't exist\n", path);
return (0); return (0);
} }
if ((file_stats.st_mode & S_IFDIR) != S_IFDIR) /* not a directory? */ if ((file_stats.st_mode & S_IFDIR) != S_IFDIR) /* not a directory? */
{ {
if (verbose) if (verbose)
fprintf (stderr, "tempname error: %s isn't a directory\n", path); fprintf (stderr, "tempname error: %s isn't a directory\n", path);
return (0); return (0);
} }
if (strchr (path, ' ') != NULL) /* contains a space character? */
{
if (verbose)
fprintf (stderr, "tempname error: %s contains a space character\n", path
);
return (0);
}
#if defined(__MINGW32__) #if defined(__MINGW32__)
if ((file_stats.st_mode & (S_IREAD | S_IWRITE)) == (S_IREAD | S_IWRITE)) /* w riteable? */ if ((file_stats.st_mode & (S_IREAD | S_IWRITE)) == (S_IREAD | S_IWRITE)) /* w riteable? */
return (1); return (1);
if (verbose) if (verbose)
fprintf (stderr, "tempname error: you don't have permission to write to %s\n ", path); fprintf (stderr, "tempname error: you don't have permission to write to %s\n ", path);
return (0); return (0);
#elif defined(DJGPP) #elif defined(DJGPP)
if ((file_stats.st_mode & S_IRWXU) == S_IRWXU) /* writeable? */ if ((file_stats.st_mode & S_IRWXU) == S_IRWXU) /* writeable? */
return (1); return (1);
if (verbose) if (verbose)
skipping to change at line 205 skipping to change at line 211
/* initialize random number generator */ /* initialize random number generator */
rand_seed (); rand_seed ();
/* generate the random name */ /* generate the random name */
for (count = 0; count < TMP_MAX; ++count) for (count = 0; count < TMP_MAX; ++count)
{ {
strcpy (copy, tmpl); strcpy (copy, tmpl);
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i)
if (copy[i] == 'X') if (copy[i] == '|')
#if defined(HAVE_LRAND48) #if defined(HAVE_LRAND48)
copy[i] = letters[(int) lrand48 () % 62]; copy[i] = letters[(int) lrand48 () % 62];
#elif defined(HAVE_RANDOM) #elif defined(HAVE_RANDOM)
copy[i] = letters[(int) random () % 62]; copy[i] = letters[(int) random () % 62];
#else #else
copy[i] = letters[(int) rand () % 62]; copy[i] = letters[(int) rand () % 62];
#endif #endif
switch (kind) switch (kind)
{ {
skipping to change at line 292 skipping to change at line 298
return (-1); return (-1);
} }
/* main program */ /* main program */
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
char *newname, *path, *suffix; char *newname, *path, *suffix;
int add_random, add_suffix, add_wild, argo, create, directory, file_id, int add_random, add_suffix, add_wild, argo, create, directory, file_id,
length, opt, path_ok, rc, user_dir, verbose; i, length, opt, path_ok, rc, user_dir, verbose;
/* parse options */ /* parse options */
add_random = 1; add_random = 1;
add_suffix = 0; add_suffix = 0;
add_wild = 0; add_wild = 0;
create = 1; create = 1;
directory = 0; directory = 0;
path = ""; path = "";
user_dir = 0; user_dir = 0;
suffix = ""; suffix = "";
skipping to change at line 420 skipping to change at line 426
if (newname[strlen (newname) - 1] != '\\') if (newname[strlen (newname) - 1] != '\\')
strcat (newname, "\\"); strcat (newname, "\\");
#else #else
if (newname[strlen (newname) - 1] != '/') if (newname[strlen (newname) - 1] != '/')
strcat (newname, "/"); strcat (newname, "/");
#endif #endif
strcat (newname, argv[optind]); strcat (newname, argv[optind]);
if (add_wild) if (add_wild)
strcat (newname, "_*"); strcat (newname, "_*");
else if (add_random) else if (add_random)
strcat (newname, "_XXXXXX"); strcat (newname, "_||||||"); /* use | instead of X in case path contains X */
if (add_suffix) if (add_suffix)
strcat (newname, suffix); strcat (newname, suffix);
/* replace spaces with underscores to reduce risk of errors in upstream script
s */
for (i = 0; i <= strlen (newname); i++)
{
if (newname[i] == ' ')
newname[i] = '_';
}
/* scramble unique letter block and optionally create temporary file */ /* scramble unique letter block and optionally create temporary file */
if (add_random) if (add_random)
{ {
if (directory) if (directory)
{ {
rc = mkstemp_custom (newname, GT_DIR); rc = mkstemp_custom (newname, GT_DIR);
if (rc < 0) if (rc < 0)
{ {
fprintf (stderr, "tempname error: can't open a tempdir for writing \n"); fprintf (stderr, "tempname error: can't open a tempdir for writing \n");
return (3); return (3);
 End of changes. 6 change blocks. 
4 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)