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
10   Copyright (C) 2000-2017 Julian Seward
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
34#include "pub_tool_basics.h"   // VG_ macro
35#include "pub_tool_vki.h"      // vki_dirent et al.
36
37/* ---------------------------------------------------------------------
38   File-related functions.
39   ------------------------------------------------------------------ */
40
41/* To use this file you must first include pub_tool_vki.h. */
42
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
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*/
55struct vg_stat {
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;
72};
73
74extern SysRes VG_(mknod)  ( const HChar* pathname, Int mode, UWord dev );
75extern SysRes VG_(open)   ( const HChar* pathname, Int flags, Int mode );
76/* fd_open words like the open(2) system call:
77   returns fd if success, -1 otherwise */
78extern Int VG_(fd_open)  (const HChar* pathname, Int flags, Int mode);
79extern void   VG_(close)  ( Int fd );
80extern Int    VG_(read)   ( Int fd, void* buf, Int count);
81extern Int    VG_(write)  ( Int fd, const void* buf, Int count);
82extern Int    VG_(pipe)   ( Int fd[2] );
83extern Off64T VG_(lseek)  ( Int fd, Off64T offset, Int whence );
84
85extern SysRes VG_(stat)   ( const HChar* file_name, struct vg_stat* buf );
86extern Int    VG_(fstat)  ( Int   fd,        struct vg_stat* buf );
87extern SysRes VG_(dup)    ( Int oldfd );
88extern SysRes VG_(dup2)   ( Int oldfd, Int newfd );
89extern Int    VG_(rename) ( const HChar* old_name, const HChar* new_name );
90extern Int    VG_(unlink) ( const HChar* file_name );
91
92extern SysRes VG_(poll) (struct vki_pollfd *fds, Int nfds, Int timeout);
93
94extern SSizeT VG_(readlink)( const HChar* path, HChar* buf, SizeT bufsiz);
95
96#if defined(VGO_linux) || defined(VGO_solaris)
97extern Int    VG_(getdents64)( Int fd, struct vki_dirent64 *dirp, UInt count );
98#endif
99
100extern const HChar* VG_(basename)( const HChar* path );
101extern const HChar* VG_(dirname) ( const HChar* path );
102
103/* Return the name of a directory for temporary files. */
104extern const HChar* VG_(tmpdir)(void);
105
106/* Return the working directory at startup. The returned string is
107   persistent. Might be NULL if the current working directory doesn't
108   exist. */
109extern const HChar *VG_(get_startup_wd) ( void );
110
111#endif   // __PUB_TOOL_LIBCFILE_H
112
113/*--------------------------------------------------------------------*/
114/*--- end                                                          ---*/
115/*--------------------------------------------------------------------*/
116