diff options
| author | Glenn Morris | 2012-12-27 00:21:08 -0800 |
|---|---|---|
| committer | Glenn Morris | 2012-12-27 00:21:08 -0800 |
| commit | 82e2a1f054cc0306494d1194036af4c5d7301caf (patch) | |
| tree | f78be2edfd92d4eba0dc28bd110f646a314438ae /src | |
| parent | c34339f3a2c425ca37bec0c6a152f913ab61f458 (diff) | |
| parent | e1da740354d9cab626bce82645adcfc6b0735b70 (diff) | |
| download | emacs-82e2a1f054cc0306494d1194036af4c5d7301caf.tar.gz emacs-82e2a1f054cc0306494d1194036af4c5d7301caf.zip | |
Merge from emacs-24; up to 2012-12-03T21:07:47Z!eggert@cs.ucla.edu
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 20 | ||||
| -rw-r--r-- | src/cygw32.c | 18 | ||||
| -rw-r--r-- | src/fileio.c | 156 |
3 files changed, 139 insertions, 55 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index d4794667ead..3fabe7579a9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,23 @@ | |||
| 1 | 2012-12-27 Glenn Morris <rgm@gnu.org> | ||
| 2 | |||
| 3 | * cygw32.c (Fcygwin_convert_file_name_to_windows) | ||
| 4 | (Fcygwin_convert_file_name_from_windows): Doc fixes. | ||
| 5 | |||
| 6 | 2012-12-27 Eli Zaretskii <eliz@gnu.org> | ||
| 7 | |||
| 8 | * fileio.c (file_name_as_directory, directory_file_name): Accept | ||
| 9 | an additional argument MULTIBYTE to indicate whether the input C | ||
| 10 | came from a multibyte or a unibyte Lisp string; all callers | ||
| 11 | adjusted. Don't assume the input string is always multibyte. | ||
| 12 | (Bug#13262) | ||
| 13 | (Ffile_name_directory) [DOS_NT]: Handle unibyte strings correctly: | ||
| 14 | don't ENCODE_FILE them, and return a unibyte string if the input | ||
| 15 | was unibyte. | ||
| 16 | (Fexpand_file_name): Don't mix unibyte with multibyte strings, and | ||
| 17 | don't assume the input strings will always be multibyte. If the | ||
| 18 | input strings are multibyte, decode strings obtained from C | ||
| 19 | library functions. | ||
| 20 | |||
| 1 | 2012-12-26 Dmitry Antipov <dmantipov@yandex.ru> | 21 | 2012-12-26 Dmitry Antipov <dmantipov@yandex.ru> |
| 2 | 22 | ||
| 3 | * lisp.h (toplevel): Add two notices to the comment about | 23 | * lisp.h (toplevel): Add two notices to the comment about |
diff --git a/src/cygw32.c b/src/cygw32.c index d9777d5e22e..5873a05dcf0 100644 --- a/src/cygw32.c +++ b/src/cygw32.c | |||
| @@ -110,23 +110,25 @@ DEFUN ("cygwin-convert-file-name-to-windows", | |||
| 110 | Fcygwin_convert_file_name_to_windows, | 110 | Fcygwin_convert_file_name_to_windows, |
| 111 | Scygwin_convert_file_name_to_windows, | 111 | Scygwin_convert_file_name_to_windows, |
| 112 | 1, 2, 0, | 112 | 1, 2, 0, |
| 113 | doc: /* Convert PATH to a Windows path. If ABSOLUTE-P is | 113 | doc: /* Convert a Cygwin file name FILE to a Windows-style file name. |
| 114 | non-nil, return an absolute path.*/) | 114 | If ABSOLUTE-P is non-nil, return an absolute file name. |
| 115 | (Lisp_Object path, Lisp_Object absolute_p) | 115 | For the reverse operation, see `cygwin-convert-file-name-from-windows'. */) |
| 116 | (Lisp_Object file, Lisp_Object absolute_p) | ||
| 116 | { | 117 | { |
| 117 | return from_unicode ( | 118 | return from_unicode ( |
| 118 | conv_filename_to_w32_unicode (path, EQ (absolute_p, Qnil) ? 0 : 1)); | 119 | conv_filename_to_w32_unicode (file, EQ (absolute_p, Qnil) ? 0 : 1)); |
| 119 | } | 120 | } |
| 120 | 121 | ||
| 121 | DEFUN ("cygwin-convert-file-name-from-windows", | 122 | DEFUN ("cygwin-convert-file-name-from-windows", |
| 122 | Fcygwin_convert_file_name_from_windows, | 123 | Fcygwin_convert_file_name_from_windows, |
| 123 | Scygwin_convert_file_name_from_windows, | 124 | Scygwin_convert_file_name_from_windows, |
| 124 | 1, 2, 0, | 125 | 1, 2, 0, |
| 125 | doc: /* Convert a Windows path to a Cygwin path. If ABSOLUTE-P | 126 | doc: /* Convert a Windows-style file name FILE to a Cygwin file name. |
| 126 | is non-nil, return an absolute path.*/) | 127 | If ABSOLUTE-P is non-nil, return an absolute file name. |
| 127 | (Lisp_Object path, Lisp_Object absolute_p) | 128 | For the reverse operation, see `cygwin-convert-file-name-to-windows'. */) |
| 129 | (Lisp_Object file, Lisp_Object absolute_p) | ||
| 128 | { | 130 | { |
| 129 | return conv_filename_from_w32_unicode (to_unicode (path, &path), | 131 | return conv_filename_from_w32_unicode (to_unicode (file, &file), |
| 130 | EQ (absolute_p, Qnil) ? 0 : 1); | 132 | EQ (absolute_p, Qnil) ? 0 : 1); |
| 131 | } | 133 | } |
| 132 | 134 | ||
diff --git a/src/fileio.c b/src/fileio.c index 50fbaa7ff04..9f70c790592 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -379,12 +379,26 @@ Given a Unix syntax file name, returns a string ending in slash. */) | |||
| 379 | strcat (res, "/"); | 379 | strcat (res, "/"); |
| 380 | beg = res; | 380 | beg = res; |
| 381 | p = beg + strlen (beg); | 381 | p = beg + strlen (beg); |
| 382 | dostounix_filename (beg); | ||
| 383 | tem_fn = make_specified_string (beg, -1, p - beg, | ||
| 384 | STRING_MULTIBYTE (filename)); | ||
| 382 | } | 385 | } |
| 386 | else | ||
| 387 | tem_fn = make_specified_string (beg - 2, -1, p - beg + 2, | ||
| 388 | STRING_MULTIBYTE (filename)); | ||
| 389 | } | ||
| 390 | else if (STRING_MULTIBYTE (filename)) | ||
| 391 | { | ||
| 392 | tem_fn = ENCODE_FILE (make_specified_string (beg, -1, p - beg, 1)); | ||
| 393 | dostounix_filename (SSDATA (tem_fn)); | ||
| 394 | tem_fn = DECODE_FILE (tem_fn); | ||
| 395 | } | ||
| 396 | else | ||
| 397 | { | ||
| 398 | dostounix_filename (beg); | ||
| 399 | tem_fn = make_specified_string (beg, -1, p - beg, 0); | ||
| 383 | } | 400 | } |
| 384 | tem_fn = ENCODE_FILE (make_specified_string (beg, -1, p - beg, | 401 | return tem_fn; |
| 385 | STRING_MULTIBYTE (filename))); | ||
| 386 | dostounix_filename (SSDATA (tem_fn)); | ||
| 387 | return DECODE_FILE (tem_fn); | ||
| 388 | #else /* DOS_NT */ | 402 | #else /* DOS_NT */ |
| 389 | return make_specified_string (beg, -1, p - beg, STRING_MULTIBYTE (filename)); | 403 | return make_specified_string (beg, -1, p - beg, STRING_MULTIBYTE (filename)); |
| 390 | #endif /* DOS_NT */ | 404 | #endif /* DOS_NT */ |
| @@ -459,12 +473,14 @@ get a current directory to run processes in. */) | |||
| 459 | return Ffile_name_directory (filename); | 473 | return Ffile_name_directory (filename); |
| 460 | } | 474 | } |
| 461 | 475 | ||
| 462 | /* Convert from file name SRC of length SRCLEN to directory name | 476 | /* Convert from file name SRC of length SRCLEN to directory name in |
| 463 | in DST. On UNIX, just make sure there is a terminating /. | 477 | DST. MULTIBYTE non-zero means the file name in SRC is a multibyte |
| 464 | Return the length of DST in bytes. */ | 478 | string. On UNIX, just make sure there is a terminating /. Return |
| 479 | the length of DST in bytes. */ | ||
| 465 | 480 | ||
| 466 | static ptrdiff_t | 481 | static ptrdiff_t |
| 467 | file_name_as_directory (char *dst, const char *src, ptrdiff_t srclen) | 482 | file_name_as_directory (char *dst, const char *src, ptrdiff_t srclen, |
| 483 | bool multibyte) | ||
| 468 | { | 484 | { |
| 469 | if (srclen == 0) | 485 | if (srclen == 0) |
| 470 | { | 486 | { |
| @@ -483,14 +499,17 @@ file_name_as_directory (char *dst, const char *src, ptrdiff_t srclen) | |||
| 483 | srclen++; | 499 | srclen++; |
| 484 | } | 500 | } |
| 485 | #ifdef DOS_NT | 501 | #ifdef DOS_NT |
| 486 | { | 502 | if (multibyte) |
| 487 | Lisp_Object tem_fn = make_specified_string (dst, -1, srclen, 1); | 503 | { |
| 504 | Lisp_Object tem_fn = make_specified_string (dst, -1, srclen, 1); | ||
| 488 | 505 | ||
| 489 | tem_fn = ENCODE_FILE (tem_fn); | 506 | tem_fn = ENCODE_FILE (tem_fn); |
| 490 | dostounix_filename (SSDATA (tem_fn)); | 507 | dostounix_filename (SSDATA (tem_fn)); |
| 491 | tem_fn = DECODE_FILE (tem_fn); | 508 | tem_fn = DECODE_FILE (tem_fn); |
| 492 | memcpy (dst, SSDATA (tem_fn), (srclen = SBYTES (tem_fn)) + 1); | 509 | memcpy (dst, SSDATA (tem_fn), (srclen = SBYTES (tem_fn)) + 1); |
| 493 | } | 510 | } |
| 511 | else | ||
| 512 | dostounix_filename (dst); | ||
| 494 | #endif | 513 | #endif |
| 495 | return srclen; | 514 | return srclen; |
| 496 | } | 515 | } |
| @@ -526,16 +545,18 @@ For a Unix-syntax file name, just appends a slash. */) | |||
| 526 | } | 545 | } |
| 527 | 546 | ||
| 528 | buf = alloca (SBYTES (file) + 10); | 547 | buf = alloca (SBYTES (file) + 10); |
| 529 | length = file_name_as_directory (buf, SSDATA (file), SBYTES (file)); | 548 | length = file_name_as_directory (buf, SSDATA (file), SBYTES (file), |
| 549 | STRING_MULTIBYTE (file)); | ||
| 530 | return make_specified_string (buf, -1, length, STRING_MULTIBYTE (file)); | 550 | return make_specified_string (buf, -1, length, STRING_MULTIBYTE (file)); |
| 531 | } | 551 | } |
| 532 | 552 | ||
| 533 | /* Convert from directory name SRC of length SRCLEN to | 553 | /* Convert from directory name SRC of length SRCLEN to file name in |
| 534 | file name in DST. On UNIX, just make sure there isn't | 554 | DST. MULTIBYTE non-zero means the file name in SRC is a multibyte |
| 535 | a terminating /. Return the length of DST in bytes. */ | 555 | string. On UNIX, just make sure there isn't a terminating /. |
| 556 | Return the length of DST in bytes. */ | ||
| 536 | 557 | ||
| 537 | static ptrdiff_t | 558 | static ptrdiff_t |
| 538 | directory_file_name (char *dst, char *src, ptrdiff_t srclen) | 559 | directory_file_name (char *dst, char *src, ptrdiff_t srclen, bool multibyte) |
| 539 | { | 560 | { |
| 540 | /* Process as Unix format: just remove any final slash. | 561 | /* Process as Unix format: just remove any final slash. |
| 541 | But leave "/" unchanged; do not change it to "". */ | 562 | But leave "/" unchanged; do not change it to "". */ |
| @@ -551,14 +572,17 @@ directory_file_name (char *dst, char *src, ptrdiff_t srclen) | |||
| 551 | srclen--; | 572 | srclen--; |
| 552 | } | 573 | } |
| 553 | #ifdef DOS_NT | 574 | #ifdef DOS_NT |
| 554 | { | 575 | if (multibyte) |
| 555 | Lisp_Object tem_fn = make_specified_string (dst, -1, srclen, 1); | 576 | { |
| 577 | Lisp_Object tem_fn = make_specified_string (dst, -1, srclen, 1); | ||
| 556 | 578 | ||
| 557 | tem_fn = ENCODE_FILE (tem_fn); | 579 | tem_fn = ENCODE_FILE (tem_fn); |
| 558 | dostounix_filename (SSDATA (tem_fn)); | 580 | dostounix_filename (SSDATA (tem_fn)); |
| 559 | tem_fn = DECODE_FILE (tem_fn); | 581 | tem_fn = DECODE_FILE (tem_fn); |
| 560 | memcpy (dst, SSDATA (tem_fn), (srclen = SBYTES (tem_fn)) + 1); | 582 | memcpy (dst, SSDATA (tem_fn), (srclen = SBYTES (tem_fn)) + 1); |
| 561 | } | 583 | } |
| 584 | else | ||
| 585 | dostounix_filename (dst); | ||
| 562 | #endif | 586 | #endif |
| 563 | return srclen; | 587 | return srclen; |
| 564 | } | 588 | } |
| @@ -594,7 +618,8 @@ In Unix-syntax, this function just removes the final slash. */) | |||
| 594 | } | 618 | } |
| 595 | 619 | ||
| 596 | buf = alloca (SBYTES (directory) + 20); | 620 | buf = alloca (SBYTES (directory) + 20); |
| 597 | length = directory_file_name (buf, SSDATA (directory), SBYTES (directory)); | 621 | length = directory_file_name (buf, SSDATA (directory), SBYTES (directory), |
| 622 | STRING_MULTIBYTE (directory)); | ||
| 598 | return make_specified_string (buf, -1, length, STRING_MULTIBYTE (directory)); | 623 | return make_specified_string (buf, -1, length, STRING_MULTIBYTE (directory)); |
| 599 | } | 624 | } |
| 600 | 625 | ||
| @@ -1044,7 +1069,7 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1044 | /* `egetenv' may return a unibyte string, which will bite us since | 1069 | /* `egetenv' may return a unibyte string, which will bite us since |
| 1045 | we expect the directory to be multibyte. */ | 1070 | we expect the directory to be multibyte. */ |
| 1046 | tem = build_string (newdir); | 1071 | tem = build_string (newdir); |
| 1047 | if (!STRING_MULTIBYTE (tem)) | 1072 | if (multibyte && !STRING_MULTIBYTE (tem)) |
| 1048 | { | 1073 | { |
| 1049 | hdir = DECODE_FILE (tem); | 1074 | hdir = DECODE_FILE (tem); |
| 1050 | newdir = SSDATA (hdir); | 1075 | newdir = SSDATA (hdir); |
| @@ -1066,7 +1091,18 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1066 | unblock_input (); | 1091 | unblock_input (); |
| 1067 | if (pw) | 1092 | if (pw) |
| 1068 | { | 1093 | { |
| 1094 | Lisp_Object tem; | ||
| 1095 | |||
| 1069 | newdir = pw->pw_dir; | 1096 | newdir = pw->pw_dir; |
| 1097 | /* `getpwnam' may return a unibyte string, which will | ||
| 1098 | bite us since we expect the directory to be | ||
| 1099 | multibyte. */ | ||
| 1100 | tem = build_string (newdir); | ||
| 1101 | if (multibyte && !STRING_MULTIBYTE (tem)) | ||
| 1102 | { | ||
| 1103 | hdir = DECODE_FILE (tem); | ||
| 1104 | newdir = SSDATA (hdir); | ||
| 1105 | } | ||
| 1070 | nm = p; | 1106 | nm = p; |
| 1071 | #ifdef DOS_NT | 1107 | #ifdef DOS_NT |
| 1072 | collapse_newdir = 0; | 1108 | collapse_newdir = 0; |
| @@ -1090,6 +1126,13 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1090 | adir = alloca (MAXPATHLEN + 1); | 1126 | adir = alloca (MAXPATHLEN + 1); |
| 1091 | if (!getdefdir (c_toupper (drive) - 'A' + 1, adir)) | 1127 | if (!getdefdir (c_toupper (drive) - 'A' + 1, adir)) |
| 1092 | adir = NULL; | 1128 | adir = NULL; |
| 1129 | else if (multibyte) | ||
| 1130 | { | ||
| 1131 | Lisp_Object tem = build_string (adir); | ||
| 1132 | |||
| 1133 | tem = DECODE_FILE (tem); | ||
| 1134 | memcpy (adir, SSDATA (tem), SBYTES (tem) + 1); | ||
| 1135 | } | ||
| 1093 | } | 1136 | } |
| 1094 | if (!adir) | 1137 | if (!adir) |
| 1095 | { | 1138 | { |
| @@ -1148,6 +1191,7 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1148 | indirectly by prepending newdir to nm if necessary, and using | 1191 | indirectly by prepending newdir to nm if necessary, and using |
| 1149 | cwd (or the wd of newdir's drive) as the new newdir. */ | 1192 | cwd (or the wd of newdir's drive) as the new newdir. */ |
| 1150 | char *adir; | 1193 | char *adir; |
| 1194 | |||
| 1151 | if (IS_DRIVE (newdir[0]) && IS_DEVICE_SEP (newdir[1])) | 1195 | if (IS_DRIVE (newdir[0]) && IS_DEVICE_SEP (newdir[1])) |
| 1152 | { | 1196 | { |
| 1153 | drive = (unsigned char) newdir[0]; | 1197 | drive = (unsigned char) newdir[0]; |
| @@ -1157,7 +1201,7 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1157 | { | 1201 | { |
| 1158 | ptrdiff_t newlen = strlen (newdir); | 1202 | ptrdiff_t newlen = strlen (newdir); |
| 1159 | char *tmp = alloca (newlen + strlen (nm) + 2); | 1203 | char *tmp = alloca (newlen + strlen (nm) + 2); |
| 1160 | file_name_as_directory (tmp, newdir, newlen); | 1204 | file_name_as_directory (tmp, newdir, newlen, multibyte); |
| 1161 | strcat (tmp, nm); | 1205 | strcat (tmp, nm); |
| 1162 | nm = tmp; | 1206 | nm = tmp; |
| 1163 | } | 1207 | } |
| @@ -1165,10 +1209,17 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1165 | if (drive) | 1209 | if (drive) |
| 1166 | { | 1210 | { |
| 1167 | if (!getdefdir (c_toupper (drive) - 'A' + 1, adir)) | 1211 | if (!getdefdir (c_toupper (drive) - 'A' + 1, adir)) |
| 1168 | newdir = "/"; | 1212 | strcpy (adir, "/"); |
| 1169 | } | 1213 | } |
| 1170 | else | 1214 | else |
| 1171 | getcwd (adir, MAXPATHLEN + 1); | 1215 | getcwd (adir, MAXPATHLEN + 1); |
| 1216 | if (multibyte) | ||
| 1217 | { | ||
| 1218 | Lisp_Object tem = build_string (adir); | ||
| 1219 | |||
| 1220 | tem = DECODE_FILE (tem); | ||
| 1221 | memcpy (adir, SSDATA (tem), SBYTES (tem) + 1); | ||
| 1222 | } | ||
| 1172 | newdir = adir; | 1223 | newdir = adir; |
| 1173 | } | 1224 | } |
| 1174 | 1225 | ||
| @@ -1255,7 +1306,7 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1255 | strcpy (target, newdir); | 1306 | strcpy (target, newdir); |
| 1256 | } | 1307 | } |
| 1257 | else | 1308 | else |
| 1258 | file_name_as_directory (target, newdir, length); | 1309 | file_name_as_directory (target, newdir, length, multibyte); |
| 1259 | } | 1310 | } |
| 1260 | 1311 | ||
| 1261 | strcat (target, nm); | 1312 | strcat (target, nm); |
| @@ -1341,9 +1392,14 @@ filesystem tree, not (expand-file-name ".." dirname). */) | |||
| 1341 | target[1] = ':'; | 1392 | target[1] = ':'; |
| 1342 | } | 1393 | } |
| 1343 | result = make_specified_string (target, -1, o - target, multibyte); | 1394 | result = make_specified_string (target, -1, o - target, multibyte); |
| 1344 | result = ENCODE_FILE (result); | 1395 | if (multibyte) |
| 1345 | dostounix_filename (SSDATA (result)); | 1396 | { |
| 1346 | result = DECODE_FILE (result); | 1397 | result = ENCODE_FILE (result); |
| 1398 | dostounix_filename (SSDATA (result)); | ||
| 1399 | result = DECODE_FILE (result); | ||
| 1400 | } | ||
| 1401 | else | ||
| 1402 | dostounix_filename (SSDATA (result)); | ||
| 1347 | #else /* !DOS_NT */ | 1403 | #else /* !DOS_NT */ |
| 1348 | result = make_specified_string (target, -1, o - target, multibyte); | 1404 | result = make_specified_string (target, -1, o - target, multibyte); |
| 1349 | #endif /* !DOS_NT */ | 1405 | #endif /* !DOS_NT */ |
| @@ -1625,18 +1681,24 @@ those `/' is discarded. */) | |||
| 1625 | memcpy (nm, SDATA (filename), SBYTES (filename) + 1); | 1681 | memcpy (nm, SDATA (filename), SBYTES (filename) + 1); |
| 1626 | 1682 | ||
| 1627 | #ifdef DOS_NT | 1683 | #ifdef DOS_NT |
| 1628 | { | 1684 | if (multibyte) |
| 1629 | Lisp_Object encoded_filename = ENCODE_FILE (filename); | 1685 | { |
| 1630 | Lisp_Object tem_fn; | 1686 | Lisp_Object encoded_filename = ENCODE_FILE (filename); |
| 1631 | 1687 | Lisp_Object tem_fn; | |
| 1632 | dostounix_filename (SDATA (encoded_filename)); | 1688 | |
| 1633 | tem_fn = DECODE_FILE (encoded_filename); | 1689 | dostounix_filename (SDATA (encoded_filename)); |
| 1634 | nm = alloca (SBYTES (tem_fn) + 1); | 1690 | tem_fn = DECODE_FILE (encoded_filename); |
| 1635 | memcpy (nm, SDATA (tem_fn), SBYTES (tem_fn) + 1); | 1691 | nm = alloca (SBYTES (tem_fn) + 1); |
| 1636 | substituted = (memcmp (nm, SDATA (filename), SBYTES (filename)) != 0); | 1692 | memcpy (nm, SDATA (tem_fn), SBYTES (tem_fn) + 1); |
| 1637 | if (substituted) | 1693 | substituted = (memcmp (nm, SDATA (filename), SBYTES (filename)) != 0); |
| 1638 | filename = tem_fn; | 1694 | if (substituted) |
| 1639 | } | 1695 | filename = tem_fn; |
| 1696 | } | ||
| 1697 | else | ||
| 1698 | { | ||
| 1699 | dostounix_filename (nm); | ||
| 1700 | substituted = (memcmp (nm, SDATA (filename), SBYTES (filename)) != 0); | ||
| 1701 | } | ||
| 1640 | #endif | 1702 | #endif |
| 1641 | endp = nm + SBYTES (filename); | 1703 | endp = nm + SBYTES (filename); |
| 1642 | 1704 | ||