OLD | NEW |
1 // sysfile_posix.go -- POSIX File handling. | 1 // sysfile_posix.go -- POSIX File handling. |
2 | 2 |
3 // Copyright 2010 The Go Authors. All rights reserved. | 3 // Copyright 2010 The Go Authors. All rights reserved. |
4 // Use of this source code is governed by a BSD-style | 4 // Use of this source code is governed by a BSD-style |
5 // license that can be found in the LICENSE file. | 5 // license that can be found in the LICENSE file. |
6 | 6 |
7 // Support for basic Unix file operations. This file simply | 7 // Support for basic Unix file operations. This file simply |
8 // translates from Go data types to Unix data types, and handles | 8 // translates from Go data types to Unix data types, and handles |
9 // errno. FIXME: This could probably be done mechanically. | 9 // errno. FIXME: This could probably be done mechanically. |
10 | 10 |
11 package syscall | 11 package syscall |
12 | 12 |
13 import "unsafe" | 13 import "unsafe" |
14 | 14 |
15 func libc_open(name *byte, mode int, perm Mode_t) int __asm__ ("open"); | 15 func libc_open(name *byte, mode int, perm Mode_t) int __asm__ ("open"); |
16 func libc_close(fd int) int __asm__ ("close"); | 16 func libc_close(fd int) int __asm__ ("close"); |
17 func libc_read(fd int, buf *byte, count Size_t) Ssize_t __asm__ ("read"); | 17 func libc_read(fd int, buf *byte, count Size_t) Ssize_t __asm__ ("read"); |
18 func libc_write(fd int, buf *byte, count Size_t) Ssize_t __asm__ ("write"); | 18 func libc_write(fd int, buf *byte, count Size_t) Ssize_t __asm__ ("write"); |
| 19 func libc_fsync(fd int) int __asm__ ("fsync") |
19 func libc_pipe(filedes *int) int __asm__("pipe"); | 20 func libc_pipe(filedes *int) int __asm__("pipe"); |
20 func libc_stat(name *byte, buf *Stat_t) int __asm__ ("stat"); | 21 func libc_stat(name *byte, buf *Stat_t) int __asm__ ("stat"); |
21 func libc_fstat(fd int, buf *Stat_t) int __asm__ ("fstat"); | 22 func libc_fstat(fd int, buf *Stat_t) int __asm__ ("fstat"); |
22 func libc_lstat(name *byte, buf *Stat_t) int __asm__ ("lstat"); | 23 func libc_lstat(name *byte, buf *Stat_t) int __asm__ ("lstat"); |
23 func libc_unlink(name *byte) int __asm__ ("unlink"); | 24 func libc_unlink(name *byte) int __asm__ ("unlink"); |
24 func libc_rmdir(name *byte) int __asm__ ("rmdir"); | 25 func libc_rmdir(name *byte) int __asm__ ("rmdir"); |
25 func libc_fcntl(fd int, cmd int, arg int) int __asm__ ("fcntl"); | 26 func libc_fcntl(fd int, cmd int, arg int) int __asm__ ("fcntl"); |
26 func libc_mkdir(name *byte, perm Mode_t) int __asm__ ("mkdir"); | 27 func libc_mkdir(name *byte, perm Mode_t) int __asm__ ("mkdir"); |
27 func libc_dup(int) int __asm__ ("dup") | 28 func libc_dup(int) int __asm__ ("dup") |
28 func libc_gettimeofday(tv *Timeval, tz *byte) int __asm__ ("gettimeofday"); | 29 func libc_gettimeofday(tv *Timeval, tz *byte) int __asm__ ("gettimeofday"); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 81 |
81 func Write(fd int, p []byte) (n int, errno int) { | 82 func Write(fd int, p []byte) (n int, errno int) { |
82 var _p0 *byte; | 83 var _p0 *byte; |
83 if len(p) > 0 { _p0 = &p[0]; } | 84 if len(p) > 0 { _p0 = &p[0]; } |
84 r := libc_write(fd, _p0, Size_t(len(p))); | 85 r := libc_write(fd, _p0, Size_t(len(p))); |
85 if r == -1 { errno = GetErrno() } | 86 if r == -1 { errno = GetErrno() } |
86 n = int(r); | 87 n = int(r); |
87 return; | 88 return; |
88 } | 89 } |
89 | 90 |
| 91 func Fsync(fd int) (errno int) { |
| 92 if libc_fsync(fd) < 0 { |
| 93 errno = GetErrno() |
| 94 } |
| 95 return |
| 96 } |
| 97 |
90 func Pread(fd int, p []byte, offset int64) (n int, errno int) { | 98 func Pread(fd int, p []byte, offset int64) (n int, errno int) { |
91 var _p0 *byte; | 99 var _p0 *byte; |
92 if len(p) > 0 { _p0 = &p[0]; } | 100 if len(p) > 0 { _p0 = &p[0]; } |
93 r := libc_pread(fd, _p0, Size_t(len(p)), Offset_t(offset)); | 101 r := libc_pread(fd, _p0, Size_t(len(p)), Offset_t(offset)); |
94 if r == -1 { errno = GetErrno() } | 102 if r == -1 { errno = GetErrno() } |
95 n = int(r); | 103 n = int(r); |
96 return; | 104 return; |
97 } | 105 } |
98 | 106 |
99 func Pwrite(fd int, p []byte, offset int64) (n int, errno int) { | 107 func Pwrite(fd int, p []byte, offset int64) (n int, errno int) { |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 return int(libc_getppid()); | 421 return int(libc_getppid()); |
414 } | 422 } |
415 | 423 |
416 func Kill(pid int, sig int) (errno int) { | 424 func Kill(pid int, sig int) (errno int) { |
417 r := libc_kill(Pid_t(pid), sig) | 425 r := libc_kill(Pid_t(pid), sig) |
418 if r < 0 { | 426 if r < 0 { |
419 errno = GetErrno() | 427 errno = GetErrno() |
420 } | 428 } |
421 return | 429 return |
422 } | 430 } |
OLD | NEW |