Home | History | Annotate | Download | only in include
      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-2012 Julian Seward
     11       jseward (at) 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 /* ---------------------------------------------------------------------
     35    File-related functions.
     36    ------------------------------------------------------------------ */
     37 
     38 /* To use this file you must first include pub_tool_vki.h. */
     39 
     40 /* Note that VG_(stat) and VG_(fstat) write to a 'struct vg_stat*' and
     41    not a 'struct vki_stat*' or a 'struct vki_stat64*'.  'struct
     42    vg_stat*' is not the same as either of the vki_ versions.  No
     43    specific vki_stat{,64} kernel structure will work and is
     44    consistently available on different architectures on Linux, so we
     45    have to use this 'struct vg_stat' impedance-matching type
     46    instead.
     47 
     48    Also note that the fieldnames aren't prefixed with "st_".  This is because
     49    st_atime et al are macros in sys/stat.h on Darwin, and using those names
     50    screws things up.
     51 */
     52 struct vg_stat {
     53    ULong   dev;
     54    ULong   ino;
     55    ULong   nlink;
     56    UInt    mode;
     57    UInt    uid;
     58    UInt    gid;
     59    ULong   rdev;
     60    Long    size;
     61    ULong   blksize;
     62    ULong   blocks;
     63    ULong   atime;
     64    ULong   atime_nsec;
     65    ULong   mtime;
     66    ULong   mtime_nsec;
     67    ULong   ctime;
     68    ULong   ctime_nsec;
     69 };
     70 
     71 extern SysRes VG_(mknod)  ( const Char* pathname, Int mode, UWord dev );
     72 extern SysRes VG_(open)   ( const Char* pathname, Int flags, Int mode );
     73 /* fd_open words like the open(2) system call:
     74    returns fd if success, -1 otherwise */
     75 extern Int VG_(fd_open)  (const Char* pathname, Int flags, Int mode);
     76 extern void   VG_(close)  ( Int fd );
     77 extern Int    VG_(read)   ( Int fd, void* buf, Int count);
     78 extern Int    VG_(write)  ( Int fd, const void* buf, Int count);
     79 extern Int    VG_(pipe)   ( Int fd[2] );
     80 extern Off64T VG_(lseek)  ( Int fd, Off64T offset, Int whence );
     81 
     82 extern SysRes VG_(stat)   ( const Char* file_name, struct vg_stat* buf );
     83 extern Int    VG_(fstat)  ( Int   fd,        struct vg_stat* buf );
     84 extern SysRes VG_(dup)    ( Int oldfd );
     85 extern SysRes VG_(dup2)   ( Int oldfd, Int newfd );
     86 extern Int    VG_(rename) ( const Char* old_name, const Char* new_name );
     87 extern Int    VG_(unlink) ( const Char* file_name );
     88 
     89 extern Int    VG_(poll) (struct vki_pollfd *fds, Int nfds, Int timeout);
     90 
     91 extern Int    VG_(readlink)( const Char* path, Char* buf, UInt bufsize );
     92 extern Int    VG_(getdents)( Int fd, struct vki_dirent *dirp, UInt count );
     93 
     94 extern Char*  VG_(basename)( const Char* path );
     95 extern Char*  VG_(dirname) ( const Char* path );
     96 
     97 /* Return the name of a directory for temporary files. */
     98 extern const HChar* VG_(tmpdir)(void);
     99 
    100 /* Copy the working directory at startup into buf[0 .. size-1], or return
    101    False if buf is too small. */
    102 extern Bool VG_(get_startup_wd) ( Char* buf, SizeT size );
    103 
    104 #endif   // __PUB_TOOL_LIBCFILE_H
    105 
    106 /*--------------------------------------------------------------------*/
    107 /*--- end                                                          ---*/
    108 /*--------------------------------------------------------------------*/
    109