"Fossies" - the Fresh Open Source Software Archive  

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

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

tempname.c  (littleutils-1.2.4.tar.lz):tempname.c  (littleutils-1.2.5.tar.lz)
skipping to change at line 22 skipping to change at line 22
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
more details. more details.
You should have received a copy of the GNU General Public License along with You should have received a copy of the GNU General Public License along with
the littleutils. If not, see <https://www.gnu.org/licenses/>. */ the littleutils. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h> #include <config.h>
#include <stdio.h> #include <errno.h>
#include <fcntl.h>
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H #ifdef HAVE_STDLIB_H
# include <stdlib.h> # include <stdlib.h>
#endif #endif
#ifdef HAVE_STRING_H #ifdef HAVE_STRING_H
# include <string.h> # include <string.h>
#endif #endif
#include <time.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H #ifdef HAVE_SYS_STAT_H
# include <sys/stat.h> # include <sys/stat.h>
#endif #endif
#include <fcntl.h> #ifdef HAVE_SYS_TYPES_H
#include <errno.h> # include <sys/types.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif #endif
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
# define OPTEND -1 # define OPTEND -1
#else #else
# define OPTEND EOF # define OPTEND EOF
#endif #endif
#ifdef HAVE_GETOPT_H
# include <getopt.h>
#endif
#include "rand_funcs.h"
#ifdef __MINGW32__ #ifdef __MINGW32__
extern int getopt (int argc, char * const *argv, const char *optstring); extern int getopt (int argc, char * const *argv, const char *optstring);
extern char *optarg; extern char *optarg;
extern int optind; extern int optind;
#include <process.h> #include <process.h>
#endif #endif
#ifdef DJGPP #ifdef DJGPP
unsigned short _djstat_flags = 63; /* speed up stat command for DJGPP */ unsigned short _djstat_flags = 63; /* speed up stat command for DJGPP */
skipping to change at line 141 skipping to change at line 144
{ {
if (file_stats.st_uid == uid) if (file_stats.st_uid == uid)
fprintf (stderr, "tempname error: permissions are incorrectly set on %s\ n", path); fprintf (stderr, "tempname error: permissions are incorrectly set on %s\ n", path);
else else
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);
#endif #endif
} }
/* random seed function */
static void
rand_seed ()
{
int URANDOM, urandom_worked = 1;
ssize_t bytes;
time_t junk;
unsigned short seed[3];
/* pre-populate array for seed using /dev/urandom */
URANDOM = open("/dev/urandom", O_RDONLY);
if (URANDOM < 0) {
urandom_worked = 0;
}
else {
/* use read instead of buffered fread to avoid grabbing extra bytes */
bytes = read(URANDOM, seed, sizeof seed);
if (bytes < 6) {
urandom_worked = 0;
}
}
close(URANDOM);
/* fall back to time and PID combo if /dev/urandom failed */
if (urandom_worked == 0) {
(void) time (&junk);
seed[0] = (unsigned short) (junk & 0xFFFF);
seed[1] = (unsigned short) (getpid () & 0xFFFF);
seed[2] = (unsigned short) ((junk >> 16) & 0xFFFF);
}
/* initialize random number generator seed */
#ifdef HAVE_LRAND48
(void) seed48 (seed);
#elif defined(HAVE_RANDOM)
srandom (((unsigned int) seed[0] << 16) + (unsigned int) seed[1]);
#else
srand (((unsigned int) seed[0] << 16) + (unsigned int) seed[1]);
#endif
}
/* special variant of mkstemp, allows X's to occur in non-end locations */ /* special variant of mkstemp, allows X's to occur in non-end locations */
static int static int
mkstemp_custom (char *tmpl, int kind) mkstemp_custom (char *tmpl, int kind)
{ {
char *copy; char *copy;
int count, fd, rc; int count, fd, rc;
int save_errno = errno; int save_errno = errno;
size_t i, len; size_t i, len;
struct stat file_stats; struct stat file_stats;
skipping to change at line 426 skipping to change at line 387
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, "_||||||"); /* use | instead of X in case path contains X */ 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 */ /* replace spaces with underscores to reduce risk of errors in upstream script s */
for (i = 0; i <= strlen (newname); i++) for (i = 0; i <= strlen (newname); i++)
{ {
if (newname[i] == ' ') if (newname[i] == ' ')
newname[i] = '_'; newname[i] = '_';
} }
 End of changes. 7 change blocks. 
53 lines changed or deleted 14 lines changed or added

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