blob: d3bd68069adbbac6eb4284dbed2d04e3216721f7 [file] [log] [blame]
njneb8896b2005-06-04 20:03:55 +00001
2/*--------------------------------------------------------------------*/
3/*--- File/socket-related libc stuff. pub_core_libcfile.h ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
9
sewardj0f157dd2013-10-18 14:27:36 +000010 Copyright (C) 2000-2013 Julian Seward
njneb8896b2005-06-04 20:03:55 +000011 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_CORE_LIBCFILE_H
32#define __PUB_CORE_LIBCFILE_H
33
34//--------------------------------------------------------------------
35// PURPOSE: This module contains all the libc code that relates to
36// files and sockets: opening, reading, writing, etc.
sewardj9a66bb92006-10-17 01:38:13 +000037// To use, you must first include: pub_core_vki.h
njneb8896b2005-06-04 20:03:55 +000038//--------------------------------------------------------------------
39
40#include "pub_tool_libcfile.h"
41
njneb8896b2005-06-04 20:03:55 +000042/* Move an fd into the Valgrind-safe range */
njn327fe8a2005-06-12 02:49:35 +000043extern Int VG_(safe_fd) ( Int oldfd );
njnbb7af3f2009-05-22 07:08:12 +000044extern Int VG_(fcntl) ( Int fd, Int cmd, Addr arg );
njneb8896b2005-06-04 20:03:55 +000045
njnae7359b2005-06-19 21:10:42 +000046/* Convert an fd into a filename */
njnf845f8f2005-06-23 02:26:47 +000047extern Bool VG_(resolve_filename) ( Int fd, HChar* buf, Int n_buf );
njnae7359b2005-06-19 21:10:42 +000048
sewardjec61b652008-08-19 07:03:04 +000049/* Return the size of a file, or -1 in case of error */
50extern Long VG_(fsize) ( Int fd );
sewardj45f4e7c2005-09-27 19:20:21 +000051
tomb7c2f9d2014-05-22 08:57:06 +000052/* Lookup an extended attribute for a file */
53extern SysRes VG_(getxattr) ( const HChar* file_name, const HChar* attr_name, Addr attr_value, SizeT attr_value_len );
54
njn73750612005-10-14 03:11:30 +000055/* Is the file a directory? */
njn63e5e6e2009-05-20 04:22:42 +000056extern Bool VG_(is_dir) ( const HChar* f );
njn73750612005-10-14 03:11:30 +000057
njne38e2332005-06-18 04:13:54 +000058/* Default destination port to be used in logging over a network, if
59 none specified. */
60#define VG_CLO_DEFAULT_LOGPORT 1500
61
florian19f91bb2012-11-10 22:29:54 +000062extern Int VG_(connect_via_socket)( const HChar* str );
njn60bd46d2009-05-21 23:52:52 +000063
toma4a4f412005-11-17 12:01:56 +000064extern UInt VG_(htonl) ( UInt x );
65extern UInt VG_(ntohl) ( UInt x );
66extern UShort VG_(htons) ( UShort x );
67extern UShort VG_(ntohs) ( UShort x );
68
njn0cd5d972009-05-22 02:00:27 +000069extern Int VG_(socket) ( Int domain, Int type, Int protocol );
70
floriandbb35842012-10-27 18:39:11 +000071extern Int VG_(write_socket)( Int sd, const void *msg, Int count );
njneb8896b2005-06-04 20:03:55 +000072extern Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *namelen );
73extern Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *namelen );
njn60bd46d2009-05-21 23:52:52 +000074extern Int VG_(getsockopt) ( Int sd, Int level, Int optname,
75 void *optval, Int *optlen );
sewardj5d616df2013-07-02 08:07:15 +000076extern Int VG_(setsockopt) ( Int sd, Int level, Int optname,
77 void *optval, Int optlen );
njneb8896b2005-06-04 20:03:55 +000078
njn63e5e6e2009-05-20 04:22:42 +000079extern Int VG_(access) ( const HChar* path, Bool irusr, Bool iwusr,
80 Bool ixusr );
sewardj45f4e7c2005-09-27 19:20:21 +000081
njn73750612005-10-14 03:11:30 +000082/* Is the file executable? Returns: 0 = success, non-0 is failure */
sewardjc74b3ba2007-11-17 21:11:57 +000083extern Int VG_(check_executable)(/*OUT*/Bool* is_setuid,
njn63e5e6e2009-05-20 04:22:42 +000084 const HChar* f, Bool allow_setuid);
njn73750612005-10-14 03:11:30 +000085
sewardj6e9de462011-06-28 07:25:29 +000086/* DDD: Note this moves (or at least, is believed to move) the file
87 pointer on Linux but doesn't on Darwin. This inconsistency should
88 be fixed. (In other words, why isn't the Linux version implemented
89 in terms of pread()?) */
njnc4431bf2009-01-15 21:29:24 +000090extern SysRes VG_(pread) ( Int fd, void* buf, Int count, OffT offset );
sewardj45f4e7c2005-09-27 19:20:21 +000091
philippecc648262013-05-26 21:09:20 +000092/* Size of fullname buffer needed for a call to VG_(mkstemp) with
93 part_of_name having the given part_of_name_len. */
94extern SizeT VG_(mkstemp_fullname_bufsz) ( SizeT part_of_name_len );
95
sewardj45f4e7c2005-09-27 19:20:21 +000096/* Create and open (-rw------) a tmp file name incorporating said arg.
97 Returns -1 on failure, else the fd of the file. If fullname is
philipped47676f2014-08-09 11:26:51 +000098 non-NULL, the file's name is written into it. The number of bytes written
99 is equal to VG_(mkstemp_fullname_bufsz)(VG_(strlen)(part_of_name)). */
100extern Int VG_(mkstemp) ( const HChar* part_of_name, /*OUT*/HChar* fullname );
sewardj45f4e7c2005-09-27 19:20:21 +0000101
sewardj198f34f2007-07-09 23:13:07 +0000102/* Record the process' working directory at startup. Is intended to
103 be called exactly once, at startup, before the working directory
104 changes. Return True for success, False for failure, so that the
105 caller can bomb out suitably without creating module cycles if
106 there is a problem. The saved value can later be acquired by
107 calling VG_(get_startup_wd) (in pub_tool_libcfile.h). */
108extern Bool VG_(record_startup_wd) ( void );
109
njneb8896b2005-06-04 20:03:55 +0000110#endif // __PUB_CORE_LIBCFILE_H
111
112/*--------------------------------------------------------------------*/
113/*--- end ---*/
114/*--------------------------------------------------------------------*/