• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * honggfuzz - file operations
4  * -----------------------------------------
5  *
6  * Author: Robert Swiecki <swiecki@google.com>
7  *
8  * Copyright 2010-2018 by Google Inc. All Rights Reserved.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License"); you may
11  * not use this file except in compliance with the License. You may obtain
12  * a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
19  * implied. See the License for the specific language governing
20  * permissions and limitations under the License.
21  *
22  */
23 
24 #ifndef _HF_COMMON_FILES_H_
25 #define _HF_COMMON_FILES_H_
26 
27 #include "common.h"
28 
29 #include <stdbool.h>
30 #include <stdint.h>
31 #include <sys/socket.h>
32 #include <unistd.h>
33 
34 extern ssize_t files_readFileToBufMax(const char* fileName, uint8_t* buf, size_t fileMaxSz);
35 
36 extern bool files_writeBufToFile(
37     const char* fileName, const uint8_t* buf, size_t fileSz, int flags);
38 
39 int files_writeBufToTmpFile(const char* dir, const uint8_t* buf, size_t fileSz, int flags);
40 
41 extern bool files_writeToFd(int fd, const uint8_t* buf, size_t fileSz);
42 
43 extern bool files_writeStrToFd(int fd, const char* str);
44 
45 extern ssize_t files_readFromFd(int fd, uint8_t* buf, size_t fileSz);
46 
47 extern ssize_t files_readFromFdSeek(int fd, uint8_t* buf, size_t fileSz, off_t pos);
48 
49 extern bool files_writePatternToFd(int fd, off_t size, unsigned char p);
50 
51 bool files_sendToSocketNB(int fd, const uint8_t* buf, size_t fileSz);
52 
53 bool files_sendToSocket(int fd, const uint8_t* buf, size_t fileSz);
54 
55 extern bool files_exists(const char* fileName);
56 
57 extern const char* files_basename(const char* path);
58 
59 extern bool files_copyFile(
60     const char* source, const char* destination, bool* dstExists, bool try_link);
61 
62 extern uint8_t* files_mapFile(const char* fileName, off_t* fileSz, int* fd, bool isWritable);
63 
64 extern uint8_t* files_mapFileShared(const char* fileName, off_t* fileSz, int* fd);
65 
66 extern void* files_mapSharedMem(size_t sz, int* fd, const char* name, const char* dir);
67 
68 extern size_t files_parseSymbolFilter(const char* inFIle, char*** filterList);
69 
70 extern sa_family_t files_sockFamily(int sock);
71 
72 extern const char* files_sockAddrToStr(const struct sockaddr* sa);
73 
74 #endif /* ifndef HF_COMMON_FILES */
75