diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 10 | ||||
| -rw-r--r-- | src/fileio.c | 79 |
2 files changed, 68 insertions, 21 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 77eb9735c7e..6a32598eb03 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2000-05-16 Gerd Moellmann <gerd@gnu.org> | ||
| 2 | |||
| 3 | * filelock.c (get_boot_time): To obtain an 8 char file name, which | ||
| 4 | is needed on mescaline, use a 2 char prefix, and call | ||
| 5 | make_temp_name with second arg non-zero. | ||
| 6 | |||
| 7 | * fileio.c (make_temp_name): New function, extracted from | ||
| 8 | Fmake_temp_name. | ||
| 9 | (Fmake_temp_name): Use it. | ||
| 10 | |||
| 1 | 2000-05-15 Eli Zaretskii <eliz@is.elta.co.il> | 11 | 2000-05-15 Eli Zaretskii <eliz@is.elta.co.il> |
| 2 | 12 | ||
| 3 | * window.c (coordinates_in_window): Subtract 1 when computing | 13 | * window.c (coordinates_in_window): Subtract 1 when computing |
diff --git a/src/fileio.c b/src/fileio.c index 0fcad5d99a2..df63786b3d1 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -839,22 +839,29 @@ static char make_temp_name_tbl[64] = | |||
| 839 | 'w','x','y','z','0','1','2','3', | 839 | 'w','x','y','z','0','1','2','3', |
| 840 | '4','5','6','7','8','9','-','_' | 840 | '4','5','6','7','8','9','-','_' |
| 841 | }; | 841 | }; |
| 842 | |||
| 842 | static unsigned make_temp_name_count, make_temp_name_count_initialized_p; | 843 | static unsigned make_temp_name_count, make_temp_name_count_initialized_p; |
| 843 | 844 | ||
| 844 | DEFUN ("make-temp-name", Fmake_temp_name, Smake_temp_name, 1, 1, 0, | 845 | /* Value is a temporary file name starting with PREFIX, a string. |
| 845 | "Generate temporary file name (string) starting with PREFIX (a string).\n\ | 846 | |
| 846 | The Emacs process number forms part of the result,\n\ | 847 | The Emacs process number forms part of the result, so there is |
| 847 | so there is no danger of generating a name being used by another process.\n\ | 848 | no danger of generating a name being used by another process. |
| 848 | \n\ | 849 | In addition, this function makes an attempt to choose a name |
| 849 | In addition, this function makes an attempt to choose a name\n\ | 850 | which has no existing file. To make this work, PREFIX should be |
| 850 | which has no existing file. To make this work,\n\ | 851 | an absolute file name. |
| 851 | PREFIX should be an absolute file name.\n\ | 852 | |
| 852 | \n\ | 853 | BASE64_P non-zero means add the pid as 3 characters in base64 |
| 853 | There is a race condition between calling `make-temp-name' and creating the\n\ | 854 | encoding. In this case, 6 characters will be added to PREFIX to |
| 854 | file which opens all kinds of security holes. For that reason, you should\n\ | 855 | form the file name. Otherwise, if Emacs is running on a system |
| 855 | probably use `make-temp-file' instead.") | 856 | with long file names, add the pid as a decimal number. |
| 856 | (prefix) | 857 | |
| 858 | This function signals an error if no unique file name could be | ||
| 859 | generated. */ | ||
| 860 | |||
| 861 | Lisp_Object | ||
| 862 | make_temp_name (prefix, base64_p) | ||
| 857 | Lisp_Object prefix; | 863 | Lisp_Object prefix; |
| 864 | int base64_p; | ||
| 858 | { | 865 | { |
| 859 | Lisp_Object val; | 866 | Lisp_Object val; |
| 860 | int len; | 867 | int len; |
| @@ -862,7 +869,7 @@ probably use `make-temp-file' instead.") | |||
| 862 | unsigned char *p, *data; | 869 | unsigned char *p, *data; |
| 863 | char pidbuf[20]; | 870 | char pidbuf[20]; |
| 864 | int pidlen; | 871 | int pidlen; |
| 865 | 872 | ||
| 866 | CHECK_STRING (prefix, 0); | 873 | CHECK_STRING (prefix, 0); |
| 867 | 874 | ||
| 868 | /* VAL is created by adding 6 characters to PREFIX. The first | 875 | /* VAL is created by adding 6 characters to PREFIX. The first |
| @@ -872,16 +879,26 @@ probably use `make-temp-file' instead.") | |||
| 872 | 879 | ||
| 873 | pid = (int) getpid (); | 880 | pid = (int) getpid (); |
| 874 | 881 | ||
| 882 | if (base64_p) | ||
| 883 | { | ||
| 884 | pidbuf[0] = make_temp_name_tbl[pid & 63], pid >>= 6; | ||
| 885 | pidbuf[1] = make_temp_name_tbl[pid & 63], pid >>= 6; | ||
| 886 | pidbuf[2] = make_temp_name_tbl[pid & 63], pid >>= 6; | ||
| 887 | pidlen = 3; | ||
| 888 | } | ||
| 889 | else | ||
| 890 | { | ||
| 875 | #ifdef HAVE_LONG_FILE_NAMES | 891 | #ifdef HAVE_LONG_FILE_NAMES |
| 876 | sprintf (pidbuf, "%d", pid); | 892 | sprintf (pidbuf, "%d", pid); |
| 877 | pidlen = strlen (pidbuf); | 893 | pidlen = strlen (pidbuf); |
| 878 | #else | 894 | #else |
| 879 | pidbuf[0] = make_temp_name_tbl[pid & 63], pid >>= 6; | 895 | pidbuf[0] = make_temp_name_tbl[pid & 63], pid >>= 6; |
| 880 | pidbuf[1] = make_temp_name_tbl[pid & 63], pid >>= 6; | 896 | pidbuf[1] = make_temp_name_tbl[pid & 63], pid >>= 6; |
| 881 | pidbuf[2] = make_temp_name_tbl[pid & 63], pid >>= 6; | 897 | pidbuf[2] = make_temp_name_tbl[pid & 63], pid >>= 6; |
| 882 | pidlen = 3; | 898 | pidlen = 3; |
| 883 | #endif | 899 | #endif |
| 884 | 900 | } | |
| 901 | |||
| 885 | len = XSTRING (prefix)->size; | 902 | len = XSTRING (prefix)->size; |
| 886 | val = make_uninit_string (len + 3 + pidlen); | 903 | val = make_uninit_string (len + 3 + pidlen); |
| 887 | data = XSTRING (val)->data; | 904 | data = XSTRING (val)->data; |
| @@ -944,6 +961,26 @@ probably use `make-temp-file' instead.") | |||
| 944 | return Qnil; | 961 | return Qnil; |
| 945 | } | 962 | } |
| 946 | 963 | ||
| 964 | |||
| 965 | DEFUN ("make-temp-name", Fmake_temp_name, Smake_temp_name, 1, 1, 0, | ||
| 966 | "Generate temporary file name (string) starting with PREFIX (a string).\n\ | ||
| 967 | The Emacs process number forms part of the result,\n\ | ||
| 968 | so there is no danger of generating a name being used by another process.\n\ | ||
| 969 | \n\ | ||
| 970 | In addition, this function makes an attempt to choose a name\n\ | ||
| 971 | which has no existing file. To make this work,\n\ | ||
| 972 | PREFIX should be an absolute file name.\n\ | ||
| 973 | \n\ | ||
| 974 | There is a race condition between calling `make-temp-name' and creating the\n\ | ||
| 975 | file which opens all kinds of security holes. For that reason, you should\n\ | ||
| 976 | probably use `make-temp-file' instead.") | ||
| 977 | (prefix) | ||
| 978 | Lisp_Object prefix; | ||
| 979 | { | ||
| 980 | return make_temp_name (prefix, 0); | ||
| 981 | } | ||
| 982 | |||
| 983 | |||
| 947 | 984 | ||
| 948 | DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0, | 985 | DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0, |
| 949 | "Convert filename NAME to absolute, and canonicalize it.\n\ | 986 | "Convert filename NAME to absolute, and canonicalize it.\n\ |