njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- File/socket-related libc stuff. pub_tool_libcfile.h ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
sewardj | 0f157dd | 2013-10-18 14:27:36 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2013 Julian Seward |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 11 | jseward@acm.org |
| 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __PUB_TOOL_LIBCFILE_H |
| 32 | #define __PUB_TOOL_LIBCFILE_H |
| 33 | |
florian | 535fb1b | 2013-09-15 13:54:34 +0000 | [diff] [blame] | 34 | #include "pub_tool_basics.h" // VG_ macro |
| 35 | #include "pub_tool_vki.h" // vki_dirent et al. |
| 36 | |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 37 | /* --------------------------------------------------------------------- |
| 38 | File-related functions. |
| 39 | ------------------------------------------------------------------ */ |
| 40 | |
sewardj | 9a66bb9 | 2006-10-17 01:38:13 +0000 | [diff] [blame] | 41 | /* To use this file you must first include pub_tool_vki.h. */ |
| 42 | |
sewardj | ec61b65 | 2008-08-19 07:03:04 +0000 | [diff] [blame] | 43 | /* Note that VG_(stat) and VG_(fstat) write to a 'struct vg_stat*' and |
| 44 | not a 'struct vki_stat*' or a 'struct vki_stat64*'. 'struct |
| 45 | vg_stat*' is not the same as either of the vki_ versions. No |
| 46 | specific vki_stat{,64} kernel structure will work and is |
| 47 | consistently available on different architectures on Linux, so we |
| 48 | have to use this 'struct vg_stat' impedance-matching type |
njn | 9c20ece | 2009-05-20 02:02:30 +0000 | [diff] [blame] | 49 | instead. |
| 50 | |
| 51 | Also note that the fieldnames aren't prefixed with "st_". This is because |
| 52 | st_atime et al are macros in sys/stat.h on Darwin, and using those names |
| 53 | screws things up. |
| 54 | */ |
sewardj | ec61b65 | 2008-08-19 07:03:04 +0000 | [diff] [blame] | 55 | struct vg_stat { |
njn | 9c20ece | 2009-05-20 02:02:30 +0000 | [diff] [blame] | 56 | ULong dev; |
| 57 | ULong ino; |
| 58 | ULong nlink; |
| 59 | UInt mode; |
| 60 | UInt uid; |
| 61 | UInt gid; |
| 62 | ULong rdev; |
| 63 | Long size; |
| 64 | ULong blksize; |
| 65 | ULong blocks; |
| 66 | ULong atime; |
| 67 | ULong atime_nsec; |
| 68 | ULong mtime; |
| 69 | ULong mtime_nsec; |
| 70 | ULong ctime; |
| 71 | ULong ctime_nsec; |
sewardj | ec61b65 | 2008-08-19 07:03:04 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 74 | extern SysRes VG_(mknod) ( const HChar* pathname, Int mode, UWord dev ); |
| 75 | extern SysRes VG_(open) ( const HChar* pathname, Int flags, Int mode ); |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 76 | /* fd_open words like the open(2) system call: |
| 77 | returns fd if success, -1 otherwise */ |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 78 | extern Int VG_(fd_open) (const HChar* pathname, Int flags, Int mode); |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 79 | extern void VG_(close) ( Int fd ); |
| 80 | extern Int VG_(read) ( Int fd, void* buf, Int count); |
| 81 | extern Int VG_(write) ( Int fd, const void* buf, Int count); |
| 82 | extern Int VG_(pipe) ( Int fd[2] ); |
tom | c17c6ef | 2011-07-13 09:02:14 +0000 | [diff] [blame] | 83 | extern Off64T VG_(lseek) ( Int fd, Off64T offset, Int whence ); |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 84 | |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 85 | extern SysRes VG_(stat) ( const HChar* file_name, struct vg_stat* buf ); |
sewardj | ec61b65 | 2008-08-19 07:03:04 +0000 | [diff] [blame] | 86 | extern Int VG_(fstat) ( Int fd, struct vg_stat* buf ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 87 | extern SysRes VG_(dup) ( Int oldfd ); |
njn | fad9837 | 2008-10-12 19:53:28 +0000 | [diff] [blame] | 88 | extern SysRes VG_(dup2) ( Int oldfd, Int newfd ); |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 89 | extern Int VG_(rename) ( const HChar* old_name, const HChar* new_name ); |
| 90 | extern Int VG_(unlink) ( const HChar* file_name ); |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 91 | |
philippe | 4254584 | 2013-12-05 22:10:55 +0000 | [diff] [blame] | 92 | extern SysRes VG_(poll) (struct vki_pollfd *fds, Int nfds, Int timeout); |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 93 | |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 94 | extern Int VG_(readlink)( const HChar* path, HChar* buf, UInt bufsize ); |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 95 | extern Int VG_(getdents)( Int fd, struct vki_dirent *dirp, UInt count ); |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 96 | |
florian | 6bd9dc1 | 2012-11-23 16:17:43 +0000 | [diff] [blame] | 97 | extern const HChar* VG_(basename)( const HChar* path ); |
| 98 | extern const HChar* VG_(dirname) ( const HChar* path ); |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 99 | |
weidendo | d585c92 | 2011-10-17 18:12:48 +0000 | [diff] [blame] | 100 | /* Return the name of a directory for temporary files. */ |
| 101 | extern const HChar* VG_(tmpdir)(void); |
| 102 | |
sewardj | 198f34f | 2007-07-09 23:13:07 +0000 | [diff] [blame] | 103 | /* Copy the working directory at startup into buf[0 .. size-1], or return |
| 104 | False if buf is too small. */ |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 105 | extern Bool VG_(get_startup_wd) ( HChar* buf, SizeT size ); |
sewardj | 198f34f | 2007-07-09 23:13:07 +0000 | [diff] [blame] | 106 | |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 107 | #endif // __PUB_TOOL_LIBCFILE_H |
| 108 | |
| 109 | /*--------------------------------------------------------------------*/ |
| 110 | /*--- end ---*/ |
| 111 | /*--------------------------------------------------------------------*/ |