Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: src/shared/platform/posix/nacl_host_desc.c

Issue 24889002: Provides some of the missing POSIX file syscalls Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/shared/platform/osx/nacl_host_dir.c ('k') | src/shared/platform/win/nacl_host_desc.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /* 7 /*
8 * NaCl Service Runtime. I/O Descriptor / Handle abstraction. Memory 8 * NaCl Service Runtime. I/O Descriptor / Handle abstraction. Memory
9 * mapping using descriptors. 9 * mapping using descriptors.
10 * 10 *
11 * Note that we avoid using the thread-specific data / thread local 11 * Note that we avoid using the thread-specific data / thread local
12 * storage access to the "errno" variable, and instead use the raw 12 * storage access to the "errno" variable, and instead use the raw
13 * system call return interface of small negative numbers as errors. 13 * system call return interface of small negative numbers as errors.
14 */ 14 */
15 15
16 #include <stdint.h> 16 #include <stdint.h>
17 #include <stdio.h>
17 #include <sys/types.h> 18 #include <sys/types.h>
18 #include <sys/stat.h> 19 #include <sys/stat.h>
19 #include <fcntl.h> 20 #include <fcntl.h>
20 #include <errno.h> 21 #include <errno.h>
21 #include <sys/mman.h> 22 #include <sys/mman.h>
22 #include <unistd.h> 23 #include <unistd.h>
23 24
24 #include "native_client/src/include/nacl_platform.h" 25 #include "native_client/src/include/nacl_platform.h"
25 #include "native_client/src/include/portability.h" 26 #include "native_client/src/include/portability.h"
26 27
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 if (getcwd(path, len) == NULL) 553 if (getcwd(path, len) == NULL)
553 return -NaClXlateErrno(errno); 554 return -NaClXlateErrno(errno);
554 return 0; 555 return 0;
555 } 556 }
556 557
557 int NaClHostDescUnlink(const char *path) { 558 int NaClHostDescUnlink(const char *path) {
558 if (unlink(path) != 0) 559 if (unlink(path) != 0)
559 return -errno; 560 return -errno;
560 return 0; 561 return 0;
561 } 562 }
563
564 int NaClHostDescTruncate(const char *path, nacl_off64_t length) {
565 #if NACL_LINUX
566 if (-1 == truncate64(path, length)) {
567 return -NaClXlateErrno(errno);
568 }
569 #elif NACL_OSX
570 if (-1 == truncate(path, length)) {
571 return -NaClXlateErrno(errno);
572 }
573 #else
574 # error Unsupported platform
575 #endif
576 return 0;
577 }
578
579 int NaClHostDescLstat(char const *host_os_pathname, nacl_host_stat_t *nhsp) {
580 #if NACL_LINUX
581 if (-1 == lstat64(host_os_pathname, nhsp)) {
582 return -NaClXlateErrno(errno);
583 }
584 #elif NACL_OSX
585 if (-1 == lstat(host_os_pathname, nhsp)) {
586 return -NaClXlateErrno(errno);
587 }
588 #else
589 # error Unsupported platform
590 #endif
591 return 0;
592 }
593
594 int NaClHostDescLink(const char *oldpath, const char *newpath) {
595 if (-1 == link(oldpath, newpath)) {
596 return -NaClXlateErrno(errno);
597 }
598 return 0;
599 }
600
601 int NaClHostDescChmod(const char *path, int mode) {
602 if (-1 == chmod(path, mode)) {
603 return -NaClXlateErrno(errno);
604 }
605 return 0;
606 }
607
608 int NaClHostDescAccess(const char *pathname, int mode) {
609 if (-1 == access(pathname, mode)) {
610 return -NaClXlateErrno(errno);
611 }
612 return 0;
613 }
614
615 int NaClHostDescRename(const char *oldpath, const char *newpath) {
616 if (-1 == rename(oldpath, newpath)) {
617 return -NaClXlateErrno(errno);
618 }
619 return 0;
620 }
621
622 int NaClHostDescReadlink(const char *path, char *buf, size_t bufsiz) {
623 if (-1 == readlink(path, buf, bufsiz)) {
624 return -NaClXlateErrno(errno);
625 }
626 return 0;
627 }
628
629 int NaClHostDescSymlink(const char *oldpath, const char *newpath) {
630 if (-1 == symlink(oldpath, newpath)) {
631 return -NaClXlateErrno(errno);
632 }
633 return 0;
634 }
635
636 int NaClHostDescUtimes(const char *filename,
637 const struct nacl_abi_timeval times[2]) {
638 struct timeval host_times[2] = {
639 {
640 .tv_sec = times[0].nacl_abi_tv_sec,
641 .tv_usec = times[0].nacl_abi_tv_usec
642 },
643 {
644 .tv_sec = times[1].nacl_abi_tv_sec,
645 .tv_usec = times[1].nacl_abi_tv_usec
646 },
647 };
648
649 if (-1 == utimes(filename, host_times)) {
650 return -NaClXlateErrno(errno);
651 }
652 return 0;
653 }
654
655 int NaClHostDescFchdir(struct NaClHostDesc *d) {
656 NaClHostDescCheckValidity("NaClHostDescFchdir", d);
657 if (-1 == fchdir(d->d)) {
658 return -NaClXlateErrno(errno);
659 }
660 return 0;
661 }
662
663 int NaClHostDescFchmod(struct NaClHostDesc *d, int mode) {
664 NaClHostDescCheckValidity("NaClHostDescFchmod", d);
665 if (-1 == fchmod(d->d, mode)) {
666 return -NaClXlateErrno(errno);
667 }
668 return 0;
669 }
670
671 int NaClHostDescFsync(struct NaClHostDesc *d) {
672 NaClHostDescCheckValidity("NaClHostDescFsync", d);
673 if (-1 == fsync(d->d)) {
674 return -NaClXlateErrno(errno);
675 }
676 return 0;
677 }
678
679 int NaClHostDescFdatasync(struct NaClHostDesc *d) {
680 NaClHostDescCheckValidity("NaClHostDescFdatasync", d);
681 if (-1 == fdatasync(d->d)) {
682 return -NaClXlateErrno(errno);
683 }
684 return 0;
685 }
686
687 int NaClHostDescFtruncate(struct NaClHostDesc *d, nacl_off64_t length) {
688 NaClHostDescCheckValidity("NaClHostDescFtruncate", d);
689 #if NACL_LINUX
690 if (-1 == ftruncate64(d->d, length)) {
691 return -NaClXlateErrno(errno);
692 }
693 #elif NACL_OSX
694 if (-1 == ftruncate(d->d, length)) {
695 return -NaClXlateErrno(errno);
696 }
697 #else
698 # error Unsupported platform
699 #endif
700 return 0;
701 }
OLDNEW
« no previous file with comments | « src/shared/platform/osx/nacl_host_dir.c ('k') | src/shared/platform/win/nacl_host_desc.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698