2 Copyright (C) 1994, 1995, 1996 the Free Software Foundation.
3 Written 1994, 1995, 1996 by:
4 Miguel de Icaza, Janne Kukonlehto, Dugan Porter,
5 Jakub Jelinek, Mauricio Plaza.
7 The file_date routine is mostly from GNU's fileutils package,
8 written by Richard Stallman and David MacKenzie.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include <sys/types.h>
30 #include <signal.h> /* my_system */
31 #include <limits.h> /* INT_MAX */
34 #include <errno.h> /* my_system */
40 #include "main.h" /* mc_home */
41 #include "cmd.h" /* guess_message_value */
42 #include "../vfs/vfs.h"
43 #include "mountlist.h"
44 #include "win.h" /* xterm_flag */
50 static const char app_text
[] = "Midnight-Commander";
51 int easy_patterns
= 1;
54 is_7bit_printable (unsigned char c
)
56 return (c
> 31 && c
< 127);
60 is_iso_printable (unsigned char c
)
62 return ((c
> 31 && c
< 127) || c
>= 160);
66 is_8bit_printable (unsigned char c
)
68 /* "Full 8 bits output" doesn't work on xterm */
70 return is_iso_printable (c
);
72 return (c
> 31 && c
!= 127 && c
!= 155);
81 /* "Display bits" is ignored, since the user controls the output
82 by setting the output codepage */
83 return is_8bit_printable (c
);
86 return is_7bit_printable (c
);
88 if (full_eight_bits
) {
89 return is_8bit_printable (c
);
91 return is_iso_printable (c
);
92 #endif /* !HAVE_CHARSET */
95 /* Returns the message dimensions (lines and columns) */
96 int msglen (char *text
, int *lines
)
101 for (*lines
= 1;*text
; text
++){
115 * Copy from s to d, and trim the beginning if necessary, and prepend
116 * "..." in this case. The destination string can have at most len
117 * bytes, not counting trailing 0.
120 trim (char *s
, char *d
, int len
)
127 source_len
= strlen (s
);
128 if (source_len
> len
) {
129 /* Cannot fit the whole line */
131 /* We only have room for the dots */
132 memset (d
, '.', len
);
136 /* Begin with ... and add the rest of the source string */
138 strcpy (d
+ 3, s
+ 3 + source_len
- len
);
141 /* We can copy the whole line */
147 name_quote (const char *s
, int quote_percent
)
151 d
= ret
= g_malloc (strlen (s
)*2 + 2 + 1);
157 for (; *s
; s
++, d
++) {
201 fake_name_quote (const char *s
, int quote_percent
)
207 * Remove the middle part of the string to fit given length.
208 * Use "~" to show where the string was truncated.
209 * Return static buffer, no need to free() it.
212 name_trunc (const char *txt
, int trunc_len
)
214 static char x
[MC_MAXPATHLEN
+ MC_MAXPATHLEN
];
218 if (trunc_len
> sizeof (x
) - 1) {
219 trunc_len
= sizeof (x
) - 1;
221 txt_len
= strlen (txt
);
222 if (txt_len
<= trunc_len
) {
225 int y
= (trunc_len
/ 2) + (trunc_len
% 2);
227 strncpy (x
+ y
, txt
+ txt_len
- (trunc_len
/ 2), trunc_len
/ 2);
232 if (!is_printable (*p
))
237 char *size_trunc (double size
)
239 static char x
[BUF_TINY
];
240 long int divisor
= 1;
243 if (size
> 999999999L){
246 if (size
/divisor
> 999999999L){
251 g_snprintf (x
, sizeof (x
), "%.0f%s", (size
/divisor
), xtra
);
255 char *size_trunc_sep (double size
)
261 p
= y
= size_trunc (size
);
263 d
= x
+ sizeof (x
) - 1;
265 while (p
>= y
&& isalpha ((unsigned char) *p
))
267 for (count
= 0; p
>= y
; count
++){
281 * Print file SIZE to BUFFER, but don't exceed LEN characters,
282 * not including trailing 0. BUFFER should be at least LEN+1 long.
283 * This function is called for every file on panels, so avoid
284 * floating point by any means.
286 * Units: size units (filesystem sizes are 1K blocks)
287 * 0=bytes, 1=Kbytes, 2=Mbytes, etc.
290 size_trunc_len (char *buffer
, int len
, off_t size
, int units
)
292 /* Avoid taking power for every file. */
293 static const off_t power10
[] =
294 {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000,
296 static const char * const suffix
[] =
297 {"", "K", "M", "G", "T", "P", "E", "Z", "Y", NULL
};
300 /* Don't print more than 9 digits - use suffix. */
301 if (len
== 0 || len
> 9)
304 for (j
= units
; suffix
[j
] != NULL
; j
++) {
307 /* Empty files will print "0" even with minimal width. */
308 g_snprintf (buffer
, len
+ 1, "0");
312 /* Use "~K" or just "K" if len is 1. Use "B" for bytes. */
313 g_snprintf (buffer
, len
+ 1, (len
> 1) ? "~%s" : "%s",
314 (j
> 1) ? suffix
[j
- 1] : "B");
318 if (size
< power10
[len
- (j
> 0)]) {
319 g_snprintf (buffer
, len
+ 1, "%lu%s", (unsigned long) size
, suffix
[j
]);
323 /* Powers of 1024, with rounding. */
324 size
= (size
+ 512) >> 10;
328 int is_exe (mode_t mode
)
330 if ((S_IXUSR
& mode
) || (S_IXGRP
& mode
) || (S_IXOTH
& mode
))
335 #define ismode(n,m) ((n & m) == m)
338 string_perm (mode_t mode_bits
)
340 static char mode
[11];
342 strcpy (mode
, "----------");
343 if (S_ISDIR (mode_bits
))
345 if (S_ISCHR (mode_bits
))
347 if (S_ISBLK (mode_bits
))
349 if (S_ISLNK (mode_bits
))
351 if (S_ISFIFO (mode_bits
))
353 if (S_ISSOCK (mode_bits
))
355 if (S_ISDOOR (mode_bits
))
357 if (ismode (mode_bits
, S_IXOTH
))
359 if (ismode (mode_bits
, S_IWOTH
))
361 if (ismode (mode_bits
, S_IROTH
))
363 if (ismode (mode_bits
, S_IXGRP
))
365 if (ismode (mode_bits
, S_IWGRP
))
367 if (ismode (mode_bits
, S_IRGRP
))
369 if (ismode (mode_bits
, S_IXUSR
))
371 if (ismode (mode_bits
, S_IWUSR
))
373 if (ismode (mode_bits
, S_IRUSR
))
376 if (ismode (mode_bits
, S_ISUID
))
377 mode
[3] = (mode
[3] == 'x') ? 's' : 'S';
380 if (ismode (mode_bits
, S_ISGID
))
381 mode
[6] = (mode
[6] == 'x') ? 's' : 'S';
384 if (ismode (mode_bits
, S_ISVTX
))
385 mode
[9] = (mode
[9] == 'x') ? 't' : 'T';
390 /* p: string which might contain an url with a password (this parameter is
392 has_prefix = 0: The first parameter is an url without a prefix
393 (user[:pass]@]machine[:port][remote-dir). Delete
395 has_prefix = 1: Search p for known url prefixes. If found delete
396 the password from the url.
397 Cavevat: only the first url is found
400 strip_password (char *p
, int has_prefix
)
402 static const struct {
405 } prefixes
[] = { {"/#ftp:", 6},
410 char *at
, *inner_colon
, *dir
;
414 for (i
= 0; i
< sizeof (prefixes
)/sizeof (prefixes
[0]); i
++) {
418 if((q
= strstr (p
, prefixes
[i
].name
)) == 0)
421 p
= q
+ prefixes
[i
].len
;
424 if ((dir
= strchr (p
, PATH_SEP
)) != NULL
)
426 /* search for any possible user */
427 at
= strchr (p
, '@');
429 /* We have a username */
432 inner_colon
= strchr (p
, ':');
435 strcpy (inner_colon
, at
);
444 char *strip_home_and_password(char *dir
)
447 static char newdir
[MC_MAXPATHLEN
];
449 if (home_dir
&& !strncmp (dir
, home_dir
, len
= strlen (home_dir
)) &&
450 (dir
[len
] == PATH_SEP
|| dir
[len
] == '\0')){
452 strcpy (&newdir
[1], &dir
[strlen (home_dir
)]);
456 /* We do not strip homes in /#ftp tree, I do not like ~'s there
458 strcpy (newdir
, dir
);
459 strip_password (newdir
, 1);
463 static char *maybe_start_group (char *d
, int do_group
, int *was_wildcard
)
475 static char *maybe_end_group (char *d
, int do_group
, int *was_wildcard
)
487 /* If shell patterns are on converts a shell pattern to a regular
488 expression. Called by regexp_match and mask_rename. */
489 /* Shouldn't we support [a-fw] type wildcards as well ?? */
490 char *convert_pattern (char *pattern
, int match_type
, int do_group
)
494 int was_wildcard
= 0;
497 new_pattern
= g_malloc (MC_MAXPATHLEN
);
499 if (match_type
== match_file
)
501 for (s
= pattern
; *s
; s
++, d
++){
504 d
= maybe_start_group (d
, do_group
, &was_wildcard
);
510 d
= maybe_start_group (d
, do_group
, &was_wildcard
);
515 d
= maybe_end_group (d
, do_group
, &was_wildcard
);
521 d
= maybe_end_group (d
, do_group
, &was_wildcard
);
526 d
= maybe_end_group (d
, do_group
, &was_wildcard
);
527 if (match_type
== match_file
)
532 return g_strdup (pattern
);
535 int regexp_match (char *pattern
, char *string
, int match_type
)
538 static char *old_pattern
= NULL
;
542 if (!old_pattern
|| STRCOMP (old_pattern
, pattern
) || old_type
!= match_type
){
545 g_free (old_pattern
);
548 pattern
= convert_pattern (pattern
, match_type
, 0);
549 if (regcomp (&r
, pattern
, REG_EXTENDED
|REG_NOSUB
|MC_ARCH_FLAGS
)) {
553 old_pattern
= pattern
;
554 old_type
= match_type
;
556 rval
= !regexec (&r
, string
, 0, NULL
, 0);
560 char *extension (char *filename
)
567 d
= filename
+ strlen (filename
) - 1;
568 for (;d
>= filename
; d
--){
575 int get_int (char *file
, char *key
, int def
)
577 return GetPrivateProfileInt (app_text
, key
, def
, file
);
580 int set_int (char *file
, char *key
, int value
)
582 char buffer
[BUF_TINY
];
584 g_snprintf (buffer
, sizeof (buffer
), "%d", value
);
585 return WritePrivateProfileString (app_text
, key
, buffer
, file
);
588 int exist_file (char *name
)
590 return access (name
, R_OK
) == 0;
593 char *load_file (char *filename
)
600 if ((data_file
= fopen (filename
, "r")) == NULL
){
603 if (fstat (fileno (data_file
), &s
) != 0){
607 data
= (char *) g_malloc (s
.st_size
+1);
608 read_size
= fread (data
, 1, s
.st_size
, data_file
);
609 data
[read_size
] = 0;
620 char *load_mc_home_file (const char *filename
, char ** allocated_filename
)
622 char *hintfile_base
, *hintfile
;
626 hintfile_base
= concat_dir_and_file (mc_home
, filename
);
627 lang
= guess_message_value ();
629 hintfile
= g_strdup_printf ("%s.%s", hintfile_base
, lang
);
630 data
= load_file (hintfile
);
634 hintfile
= g_strdup_printf ("%s.%.2s", hintfile_base
, lang
);
635 data
= load_file (hintfile
);
639 hintfile
= hintfile_base
;
640 data
= load_file (hintfile_base
);
646 if (hintfile
!= hintfile_base
)
647 g_free (hintfile_base
);
649 if (allocated_filename
)
650 *allocated_filename
= hintfile
;
657 /* Check strftime() results. Some systems (i.e. Solaris) have different
658 short-month-name sizes for different locales */
659 size_t i18n_checktimelength (void)
662 char buf
[MAX_I18NTIMELENGTH
+ 1];
663 time_t testtime
= time (NULL
);
665 a
= strftime (buf
, sizeof(buf
)-1, _("%b %e %H:%M"), localtime(&testtime
));
666 b
= strftime (buf
, sizeof(buf
)-1, _("%b %e %Y"), localtime(&testtime
));
670 /* Don't handle big differences. Use standard value (email bug, please) */
671 if ( length
> MAX_I18NTIMELENGTH
|| length
< MIN_I18NTIMELENGTH
)
672 length
= STD_I18NTIMELENGTH
;
677 char *file_date (time_t when
)
679 static char timebuf
[MAX_I18NTIMELENGTH
+ 1];
680 time_t current_time
= time ((time_t) 0);
681 static size_t i18n_timelength
= 0;
682 static char *fmtyear
, *fmttime
;
685 if (i18n_timelength
== 0){
686 i18n_timelength
= i18n_checktimelength() + 1;
688 /* strftime() format string for old dates */
689 fmtyear
= _("%b %e %Y");
690 /* strftime() format string for recent dates */
691 fmttime
= _("%b %e %H:%M");
694 if (current_time
> when
+ 6L * 30L * 24L * 60L * 60L /* Old. */
695 || current_time
< when
- 60L * 60L) /* In the future. */
696 /* The file is fairly old or in the future.
697 POSIX says the cutoff is 6 months old;
698 approximate this by 6*30 days.
699 Allow a 1 hour slop factor for what is considered "the future",
700 to allow for NFS server/client clock disagreement.
701 Show the year instead of the time of day. */
707 strftime (timebuf
, i18n_timelength
, fmt
, localtime(&when
));
711 char *extract_line (char *s
, char *top
)
713 static char tmp_line
[BUF_MEDIUM
];
716 while (*s
&& *s
!= '\n' && (t
- tmp_line
) < sizeof (tmp_line
)-1 && s
< top
)
722 /* FIXME: I should write a faster version of this (Aho-Corasick stuff) */
723 char * _icase_search (char *text
, char *data
, int *lng
)
732 while (*(e
+1) == '\b' && *(e
+2)) {
736 if (toupper((unsigned char) *d
) == toupper((unsigned char) *e
))
745 *lng
= strlen (text
) + dlng
;
752 /* The basename routine */
753 char *x_basename (char *s
)
756 return ((where
= strrchr (s
, PATH_SEP
))) ? where
+ 1 : s
;
760 char *unix_error_string (int error_num
)
762 static char buffer
[BUF_LARGE
];
764 g_snprintf (buffer
, sizeof (buffer
), "%s (%d)",
765 g_strerror (error_num
), error_num
);
769 char *skip_separators (char *s
)
772 if (*s
!= ' ' && *s
!= '\t' && *s
!= ',')
777 char *skip_numbers (char *s
)
780 if (!isdigit ((unsigned int) *s
))
785 /* Remove all control sequences from the argument string. We define
786 * "control sequence", in a sort of pidgin BNF, as follows:
788 * control-seq = Esc non-'['
789 * | Esc '[' (0 or more digits or ';' or '?') (any other char)
791 * This scheme works for all the terminals described in my termcap /
792 * terminfo databases, except the Hewlett-Packard 70092 and some Wyse
793 * terminals. If I hear from a single person who uses such a terminal
794 * with MC, I'll be glad to add support for it. (Dugan)
795 * Non-printable characters are also removed.
798 char *strip_ctrl_codes (char *s
)
800 char *w
; /* Current position where the stripped data is written */
801 char *r
; /* Current position where the original data is read */
806 for (w
= s
, r
= s
; *r
; ) {
807 if (*r
== ESC_CHAR
) {
808 /* Skip the control sequence's arguments */ ;
810 /* strchr() matches trailing binary 0 */
811 while (*(++r
) && strchr ("0123456789;?", *r
));
815 * Now we are at the last character of the sequence.
816 * Skip it unless it's binary 0.
823 if (is_printable(*r
))
833 char *get_current_wd (char *buffer
, int size
)
838 p
= g_get_current_dir ();
846 strncpy (buffer
, p
, len
);
851 #endif /* !USE_VFS */
853 /* This function returns 0 if the file is not in not compressed by
854 * one of the supported compressors (gzip, bzip, bzip2). Otherwise,
855 * the compression type is returned, as defined in util.h
856 * Warning: this function moves the current file pointer */
857 int get_compression_type (int fd
)
859 unsigned char magic
[4];
861 /* Read the magic signature */
862 if (mc_read (fd
, &magic
[0], 4) != 4)
863 return COMPRESSION_NONE
;
865 /* GZIP_MAGIC and OLD_GZIP_MAGIC */
866 if (magic
[0] == 037 && (magic
[1] == 0213 || magic
[1] == 0236)) {
867 return COMPRESSION_GZIP
;
871 if (magic
[0] == 0120 && magic
[1] == 0113 && magic
[2] == 003
872 && magic
[3] == 004) {
873 /* Read compression type */
874 mc_lseek (fd
, 8, SEEK_SET
);
875 if (mc_read (fd
, &magic
[0], 2) != 2)
876 return COMPRESSION_NONE
;
878 /* Gzip can handle only deflated (8) or stored (0) files */
879 if ((magic
[0] != 8 && magic
[0] != 0) || magic
[1] != 0)
880 return COMPRESSION_NONE
;
882 /* Compatible with gzip */
883 return COMPRESSION_GZIP
;
886 /* PACK_MAGIC and LZH_MAGIC and compress magic */
888 && (magic
[1] == 036 || magic
[1] == 0240 || magic
[1] == 0235)) {
889 /* Compatible with gzip */
890 return COMPRESSION_GZIP
;
893 /* BZIP and BZIP2 files */
894 if ((magic
[0] == 'B') && (magic
[1] == 'Z') &&
895 (magic
[3] >= '1') && (magic
[3] <= '9')) {
898 return COMPRESSION_BZIP
;
900 return COMPRESSION_BZIP2
;
907 decompress_extension (int type
)
910 case COMPRESSION_GZIP
: return "#ugz";
911 case COMPRESSION_BZIP
: return "#ubz";
912 case COMPRESSION_BZIP2
: return "#ubz2";
914 /* Should never reach this place */
915 fprintf (stderr
, "Fatal: decompress_extension called with an unknown argument\n");
920 void add_hook (Hook
**hook_list
, void (*hook_fn
)(void *), void *data
)
922 Hook
*new_hook
= g_new (Hook
, 1);
924 new_hook
->hook_fn
= hook_fn
;
925 new_hook
->next
= *hook_list
;
926 new_hook
->hook_data
= data
;
928 *hook_list
= new_hook
;
931 void execute_hooks (Hook
*hook_list
)
936 /* We copy the hook list first so tahat we let the hook
937 * function call delete_hook
941 add_hook (&new_hook
, hook_list
->hook_fn
, hook_list
->hook_data
);
942 hook_list
= hook_list
->next
;
947 (*new_hook
->hook_fn
)(new_hook
->hook_data
);
948 new_hook
= new_hook
->next
;
951 for (hook_list
= p
; hook_list
;){
953 hook_list
= hook_list
->next
;
958 void delete_hook (Hook
**hook_list
, void (*hook_fn
)(void *))
960 Hook
*current
, *new_list
, *next
;
964 for (current
= *hook_list
; current
; current
= next
){
965 next
= current
->next
;
966 if (current
->hook_fn
== hook_fn
)
969 add_hook (&new_list
, current
->hook_fn
, current
->hook_data
);
971 *hook_list
= new_list
;
974 int hook_present (Hook
*hook_list
, void (*hook_fn
)(void *))
978 for (p
= hook_list
; p
; p
= p
->next
)
979 if (p
->hook_fn
== hook_fn
)
984 void wipe_password (char *passwd
)
995 /* Convert "\E" -> esc character and ^x to control-x key and ^^ to ^ key */
996 /* Returns a newly allocated string */
997 char *convert_controls (char *s
)
999 char *valcopy
= g_strdup (s
);
1002 /* Parse the escape special character */
1003 for (p
= s
, q
= valcopy
; *p
;){
1006 if ((*p
== 'e') || (*p
== 'E')){
1017 if (*p
>= 'a' && *p
<= 'z') {
1018 *q
++ = *p
++ - 'a' + 1;
1030 /* Reverse the string */
1031 char *reverse_string (char *string
)
1033 char *str_beg
= string
;
1034 char *str_end
= string
+ strlen (string
);
1036 while (--str_end
> str_beg
){
1039 *str_end
= *str_beg
;
1045 static char *resolve_symlinks (char *path
)
1047 char *buf
, *buf2
, *p
, *q
, *r
, c
;
1051 if (*path
!= PATH_SEP
)
1053 r
= buf
= g_malloc (MC_MAXPATHLEN
);
1054 buf2
= g_malloc (MC_MAXPATHLEN
);
1059 q
= strchr (p
+ 1, PATH_SEP
);
1061 q
= strchr (p
+ 1, 0);
1067 if (mc_lstat (path
, &mybuf
) < 0) {
1073 if (!S_ISLNK (mybuf
.st_mode
))
1076 len
= mc_readlink (path
, buf2
, MC_MAXPATHLEN
);
1084 if (*buf2
== PATH_SEP
)
1089 canonicalize_pathname (buf
);
1090 r
= strchr (buf
, 0);
1091 if (!*r
|| *(r
- 1) != PATH_SEP
) {
1101 strcpy (buf
, PATH_SEP_STR
);
1102 else if (*(r
- 1) == PATH_SEP
&& r
!= buf
+ 1)
1108 /* Finds out a relative path from first to second, i.e. goes as many ..
1109 * as needed up in first and then goes down using second */
1110 char *diff_two_paths (char *first
, char *second
)
1112 char *p
, *q
, *r
, *s
, *buf
= 0;
1113 int i
, j
, prevlen
= -1, currlen
;
1115 first
= resolve_symlinks (first
);
1118 for (j
= 0; j
< 2; j
++) {
1121 second
= resolve_symlinks (second
);
1122 if (second
== NULL
) {
1129 r
= strchr (p
, PATH_SEP
);
1130 s
= strchr (q
, PATH_SEP
);
1134 if (strcmp (p
, q
)) {
1135 *r
= PATH_SEP
; *s
= PATH_SEP
;
1138 *r
= PATH_SEP
; *s
= PATH_SEP
;
1144 for (i
= 0; (p
= strchr (p
+ 1, PATH_SEP
)) != NULL
; i
++);
1145 currlen
= (i
+ 1) * 3 + strlen (q
) + 1;
1147 if (currlen
< prevlen
)
1155 p
= buf
= g_malloc (currlen
);
1157 for (; i
>= 0; i
--, p
+= 3)
1166 /* If filename is NULL, then we just append PATH_SEP to the dir */
1168 concat_dir_and_file (const char *dir
, const char *file
)
1170 int i
= strlen (dir
);
1172 if (dir
[i
-1] == PATH_SEP
)
1173 return g_strconcat (dir
, file
, NULL
);
1175 return g_strconcat (dir
, PATH_SEP_STR
, file
, NULL
);
1178 /* Following code heavily borrows from libiberty, mkstemps.c */
1180 /* Number of attempts to create a temporary file */
1182 #define TMP_MAX 16384
1183 #endif /* !TMP_MAX */
1187 * pname (output) - pointer to the name of the temp file (needs g_free).
1188 * NULL if the function fails.
1189 * prefix - part of the filename before the random part.
1190 * Prepend $TMPDIR or /tmp if there are no path separators.
1191 * suffix - if not NULL, part of the filename after the random part.
1194 * handle of the open file or -1 if couldn't open any.
1197 mc_mkstemps (char **pname
, const char *prefix
, const char *suffix
)
1199 static const char letters
[]
1200 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
1201 static unsigned long value
;
1208 if (strchr (prefix
, PATH_SEP
) == NULL
) {
1209 /* Add prefix first to find the position of XXXXXX */
1210 tmpbase
= concat_dir_and_file (mc_tmpdir (), prefix
);
1212 tmpbase
= g_strdup (prefix
);
1215 tmpname
= g_strconcat (tmpbase
, "XXXXXX", suffix
, NULL
);
1217 XXXXXX
= &tmpname
[strlen (tmpbase
)];
1220 /* Get some more or less random data. */
1221 gettimeofday (&tv
, NULL
);
1222 value
+= (tv
.tv_usec
<< 16) ^ tv
.tv_sec
^ getpid ();
1224 for (count
= 0; count
< TMP_MAX
; ++count
) {
1225 unsigned long v
= value
;
1228 /* Fill in the random bits. */
1229 XXXXXX
[0] = letters
[v
% 62];
1231 XXXXXX
[1] = letters
[v
% 62];
1233 XXXXXX
[2] = letters
[v
% 62];
1235 XXXXXX
[3] = letters
[v
% 62];
1237 XXXXXX
[4] = letters
[v
% 62];
1239 XXXXXX
[5] = letters
[v
% 62];
1241 fd
= open (tmpname
, O_RDWR
| O_CREAT
| O_TRUNC
| O_EXCL
,
1244 /* Successfully created. */
1248 /* This is a random value. It is only necessary that the next
1249 TMP_MAX values generated by adding 7777 to VALUE are different
1250 with (module 2^32). */
1254 /* Unsuccessful. Free the filename. */