ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
file.h
Go to the documentation of this file.
1#ifndef _file_h_INCLUDED
2#define _file_h_INCLUDED
3
4#include <assert.h>
5#include <stdbool.h>
6#include <stdint.h>
7#include <stdio.h>
8
9#include "attribute.h"
10#include "keatures.h"
11
12#include "global.h"
14
15bool kissat_file_exists (const char *path);
16bool kissat_file_readable (const char *path);
17bool kissat_file_writable (const char *path);
18size_t kissat_file_size (const char *path);
19bool kissat_find_executable (const char *name);
20
21typedef struct file file;
22
23struct file {
24 FILE *file;
25 bool close;
26 bool reading;
28 const char *path;
29 uint64_t bytes;
30};
31
32void kissat_read_already_open_file (file *, FILE *, const char *path);
33void kissat_write_already_open_file (file *, FILE *, const char *path);
34
35bool kissat_open_to_read_file (file *, const char *path);
36bool kissat_open_to_write_file (file *, const char *path);
37
38void kissat_close_file (file *);
39
40#ifndef KISSAT_HAS_COMPRESSION
41
42bool kissat_looks_like_a_compressed_file (const char *path);
43
44#endif
45
46// clang-format off
47
48static inline size_t
49kissat_read (file *, void *, size_t) ATTRIBUTE_ALWAYS_INLINE;
50
51static inline size_t
52kissat_write (file *, void *, size_t) ATTRIBUTE_ALWAYS_INLINE;
53
54static inline int kissat_getc (file *) ATTRIBUTE_ALWAYS_INLINE;
55
56static inline int kissat_putc (file *, int) ATTRIBUTE_ALWAYS_INLINE;
57
58static inline void kissat_flush (file *) ATTRIBUTE_ALWAYS_INLINE;
59
60// clang-format on
61
62static inline size_t kissat_read (file *file, void *ptr, size_t bytes) {
66#ifdef KISSAT_HAS_UNLOCKEDIO
67 size_t res = fread_unlocked (ptr, 1, bytes, file->file);
68#else
69 size_t res = fread (ptr, 1, bytes, file->file);
70#endif
71 file->bytes += res;
72 return res;
73}
74
75static inline size_t kissat_write (file *file, void *ptr, size_t bytes) {
79#ifdef KISSAT_HAS_UNLOCKEDIO
80 size_t res = fwrite_unlocked (ptr, 1, bytes, file->file);
81#else
82 size_t res = fwrite (ptr, 1, bytes, file->file);
83#endif
84 file->bytes += res;
85 return res;
86}
87
88static inline int kissat_getc (file *file) {
92#ifdef KISSAT_HAS_UNLOCKEDIO
93 int res = getc_unlocked (file->file);
94#else
95 int res = getc (file->file);
96#endif
97 if (res != EOF)
98 file->bytes++;
99 return res;
100}
101
102static inline int kissat_putc (file *file, int ch) {
106#ifdef KISSAT_HAS_UNLOCKEDIO
107 int res = putc_unlocked (ch, file->file);
108#else
109 int res = putc (ch, file->file);
110#endif
111 if (res != EOF)
112 file->bytes++;
113 return ch;
114}
115
116static inline void kissat_flush (file *file) {
120#ifdef KISSAT_HAS_UNLOCKEDIO
121 fflush_unlocked (file->file);
122#else
123 fflush (file->file);
124#endif
125}
126
128
129#endif
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
#define ATTRIBUTE_ALWAYS_INLINE
Definition attribute.h:15
size_t kissat_file_size(const char *path)
Definition file.c:98
void kissat_close_file(file *)
Definition file.c:308
ABC_NAMESPACE_HEADER_START bool kissat_file_exists(const char *path)
Definition file.c:22
bool kissat_open_to_read_file(file *, const char *path)
Definition file.c:237
void kissat_write_already_open_file(file *, FILE *, const char *path)
Definition file.c:207
bool kissat_open_to_write_file(file *, const char *path)
Definition file.c:272
bool kissat_file_readable(const char *path)
Definition file.c:31
bool kissat_file_writable(const char *path)
Definition file.c:42
void kissat_read_already_open_file(file *, FILE *, const char *path)
Definition file.c:198
bool kissat_find_executable(const char *name)
Definition file.c:105
bool kissat_looks_like_a_compressed_file(const char *path)
Definition file.c:219
#define KISSAT_assert(ignore)
Definition global.h:13
char * name
Definition main.h:24
Definition file.h:23
bool compressed
Definition file.h:27
FILE * file
Definition file.h:24
bool close
Definition file.h:25
bool reading
Definition file.h:26
uint64_t bytes
Definition file.h:29
const char * path
Definition file.h:28