aboutsummaryrefslogtreecommitdiffstats
path: root/src/android.c
diff options
context:
space:
mode:
authorPo Lu2023-02-25 20:11:48 +0800
committerPo Lu2023-02-25 20:11:48 +0800
commitdf29bb71fc47b5e24fa971b668e4fa09dd6d244d (patch)
tree78672c8e9f3b3db96f59a2bf6f81107d9eadb4af /src/android.c
parent8e4c5db193dc7baee5846520fe8b63d8bea99148 (diff)
downloademacs-df29bb71fc47b5e24fa971b668e4fa09dd6d244d.tar.gz
emacs-df29bb71fc47b5e24fa971b668e4fa09dd6d244d.zip
Update Android port
* java/org/gnu/emacs/EmacsNoninteractive.java (main): Port to Android 2.2. * src/android-asset.h (AAsset_openFileDescriptor): Delete stub function. * src/android.c (android_check_compressed_file): Delete function. (android_open): Stop trying to find compressed files or to use the system provided file descriptor. Explain why.
Diffstat (limited to 'src/android.c')
-rw-r--r--src/android.c65
1 files changed, 11 insertions, 54 deletions
diff --git a/src/android.c b/src/android.c
index 72c50c0a13c..40d6234d508 100644
--- a/src/android.c
+++ b/src/android.c
@@ -1376,42 +1376,6 @@ android_hack_asset_fd (AAsset *asset)
1376#endif 1376#endif
1377} 1377}
1378 1378
1379/* Read two bytes from FD and see if they are ``PK'', denoting ZIP
1380 archive compressed data. If FD is -1, return -1.
1381
1382 If they are not, rewind the file descriptor to offset 0.
1383
1384 If either operation fails, return -1 and close FD. Else, value is
1385 FD. */
1386
1387static int
1388android_check_compressed_file (int fd)
1389{
1390 char bytes[2];
1391
1392 if (fd == -1)
1393 return -1;
1394
1395 if (read (fd, bytes, 2) != 2)
1396 goto lseek_back;
1397
1398 if (bytes[0] != 'P' || bytes[1] != 'K')
1399 goto lseek_back;
1400
1401 /* This could be compressed data! */
1402 return -1;
1403
1404 lseek_back:
1405 /* Seek back to offset 0. If this fails, return -1. */
1406 if (lseek (fd, 0, SEEK_SET) != 0)
1407 {
1408 close (fd);
1409 return -1;
1410 }
1411
1412 return fd;
1413}
1414
1415/* Make FD close-on-exec. If any system call fails, do not abort, but 1379/* Make FD close-on-exec. If any system call fails, do not abort, but
1416 log a warning to the system log. */ 1380 log a warning to the system log. */
1417 1381
@@ -1482,28 +1446,21 @@ android_open (const char *filename, int oflag, int mode)
1482 return -1; 1446 return -1;
1483 } 1447 }
1484 1448
1485 /* Try to obtain the file descriptor corresponding to this 1449 /* Create a shared memory file descriptor containing the asset
1486 asset. */ 1450 contents.
1487 fd = AAsset_openFileDescriptor (asset, &out_start, 1451
1488 &out_length); 1452 The documentation misleads people into thinking that
1453 AAsset_openFileDescriptor does precisely this. However, it
1454 instead returns an offset into any uncompressed assets in the
1455 ZIP archive. This cannot be found in its documentation. */
1489 1456
1490 /* The platform sometimes returns a file descriptor to ZIP 1457 fd = android_hack_asset_fd (asset);
1491 compressed data. Detect that and fall back to creating a
1492 shared memory file descriptor. */
1493 fd = android_check_compressed_file (fd);
1494 1458
1495 if (fd == -1) 1459 if (fd == -1)
1496 { 1460 {
1497 /* The asset can't be accessed for some reason. Try to 1461 AAsset_close (asset);
1498 create a shared memory file descriptor. */ 1462 errno = ENXIO;
1499 fd = android_hack_asset_fd (asset); 1463 return -1;
1500
1501 if (fd == -1)
1502 {
1503 AAsset_close (asset);
1504 errno = ENXIO;
1505 return -1;
1506 }
1507 } 1464 }
1508 1465
1509 /* If O_CLOEXEC is specified, make the file descriptor close on 1466 /* If O_CLOEXEC is specified, make the file descriptor close on