diff options
| author | Richard M. Stallman | 1998-05-02 06:00:42 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-05-02 06:00:42 +0000 |
| commit | 8a7777fc1a5625685fab4ddbc5f6031ab591efb3 (patch) | |
| tree | aad55a65446090570f3b90524cdec072b547d0f5 /src | |
| parent | ba88b3223836b75b75c3906618de59f3b409e920 (diff) | |
| download | emacs-8a7777fc1a5625685fab4ddbc5f6031ab591efb3.tar.gz emacs-8a7777fc1a5625685fab4ddbc5f6031ab591efb3.zip | |
(Fmake_temp_name): Improve randomness of generated file names.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/fileio.c b/src/fileio.c index b1ad711555d..16350504669 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -862,12 +862,17 @@ PREFIX should be an absolute file name.") | |||
| 862 | while (1) | 862 | while (1) |
| 863 | { | 863 | { |
| 864 | struct stat ignored; | 864 | struct stat ignored; |
| 865 | unsigned num = make_temp_name_count++; | 865 | unsigned num = make_temp_name_count; |
| 866 | 866 | ||
| 867 | p[0] = make_temp_name_tbl[num & 63], num >>= 6; | 867 | p[0] = make_temp_name_tbl[num & 63], num >>= 6; |
| 868 | p[1] = make_temp_name_tbl[num & 63], num >>= 6; | 868 | p[1] = make_temp_name_tbl[num & 63], num >>= 6; |
| 869 | p[2] = make_temp_name_tbl[num & 63], num >>= 6; | 869 | p[2] = make_temp_name_tbl[num & 63], num >>= 6; |
| 870 | 870 | ||
| 871 | /* Poor man's congruential RN generator. Replace with | ||
| 872 | ++make_temp_name_count for debugging. */ | ||
| 873 | make_temp_name_count += 25229; | ||
| 874 | make_temp_name_count %= 225307; | ||
| 875 | |||
| 871 | if (stat (data, &ignored) < 0) | 876 | if (stat (data, &ignored) < 0) |
| 872 | { | 877 | { |
| 873 | /* We want to return only if errno is ENOENT. */ | 878 | /* We want to return only if errno is ENOENT. */ |
| @@ -878,9 +883,9 @@ PREFIX should be an absolute file name.") | |||
| 878 | can do. The alternatives are to return nil, which is | 883 | can do. The alternatives are to return nil, which is |
| 879 | as bad as (and in many cases worse than) throwing the | 884 | as bad as (and in many cases worse than) throwing the |
| 880 | error, or to ignore the error, which will likely result | 885 | error, or to ignore the error, which will likely result |
| 881 | in looping through 262144 stat's, which is not only | 886 | in looping through 225307 stat's, which is not only |
| 882 | SLOW, but also useless since it will fallback to the | 887 | dog-slow, but also useless since it will fallback to |
| 883 | errow below, anyway. */ | 888 | the errow below, anyway. */ |
| 884 | report_file_error ("Cannot create temporary name for prefix `%s'", | 889 | report_file_error ("Cannot create temporary name for prefix `%s'", |
| 885 | Fcons (prefix, Qnil)); | 890 | Fcons (prefix, Qnil)); |
| 886 | /* not reached */ | 891 | /* not reached */ |