Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BLI_bfile.h « blenlib « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8c93e03c881ac1b061cb7449ac2df5d2b77567d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * $Id$
 *
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * The Original Code is Copyright (C) 2009 by Stichting Blender Foundation.
 * All rights reserved.
 *
 * ***** END GPL LICENSE BLOCK *****
 * BFILE* based abstraction of file access.
 */

#ifndef BLI_BFILE_H
#define BLI_BFILE_H

/* For fopen's FILE */
#include <stdio.h>

/**
 Defines for the bflags param.
 */
/* Special handling: */
/* For "symmetry" of flags */
#define BFILE_NORMAL (0)
/* No supervision, just translate // if needed, RISKY */
#define BFILE_RAW    (1<<0)
/* Path is based in env vars specified by "envvars" */
#define BFILE_CONFIG (1<<1)
/* Path is for current session temp files */
#define BFILE_TEMP   (1<<2)

/* Config handling, special cases: */
#define BFILE_USERONLY (1<<3)
#define BFILE_SYSONLY  (1<<4)

/* Compression to apply on close: */
#define BFILE_GZIP (1<<5)

/**
 For the envvars param.
 */
typedef enum BEnvVarFamilies {
	BENV_NONE,
	BENV_BASE,
	BENV_DATAFILES,
	BENV_PYTHON,
	BENV_PLUGINS
} BEnvVarFam;

/**
 File descriptor for Blender abstracted file access.
 */
typedef struct {
	FILE *stream;
	int fd;

	/* Anything below should not be touched directly */
	int uflags;       /* Special options requested by upper level, copy of bflags */
	BEnvVarFam evars; /* What kind of file, describe the env vars to use */
	char *fpath;      /* Final/requested path name */
	char *tpath;      /* Temp path name if applicable */
	int classf;       /* Own flags, common classification of open and fopen */
	int error;        /* An op caused an error, unsafe to replace older files */
} BFILE;

/**
 Open a BFILE* with fopen()-like syntax.
 */
BFILE *BLI_bfile_fopen(const char *path, const char *mode, int bflags, BEnvVarFam envvars);

/**
 Open a BFILE* with open()-like syntax.
 */
BFILE *BLI_bfile_open(const char *pathname, int flags, int bflags, BEnvVarFam envvars);

/**
 Get the FILE* associated with the BFILE*.
 */
FILE *BLI_bfile_file_from_bfile(BFILE *bfile);

/**
 Get the fd associated with the BFILE*.
 */
int BLI_bfile_fd_from_bfile(BFILE *bfile);

/**
 write()-like using BFILE*.
 */
ssize_t BLI_bfile_write(BFILE *f, const void *buf, size_t count);

/**
 read()-like using BFILE*.
 */
ssize_t BLI_bfile_read(BFILE *f, void *buf, size_t count);

/**
 fwrite()-like using BFILE*.
 */
size_t BLI_bfile_fwrite(const void *ptr, size_t size, size_t nmemb, BFILE *f);

/**
 fread()-like using BFILE*.
 */
size_t BLI_bfile_fread(void *ptr, size_t size, size_t nmemb, BFILE *f);

/**
 Close a BFILE, to match close() and fclose().
 */
void BLI_bfile_close(BFILE *bfile);

/**
 Clear error status.
 Call it only if the error has been really handled.
 */
void BLI_bfile_clear_error(BFILE *bfile);

/**
 Set the error status.
 Call it to mark writing by a 3rd party failed (libjpeg reported error, ie).
 */
void BLI_bfile_set_error(BFILE *bfile, int error);

/*
TODO
Maybe also provide more OS/libc things like:
fflush
fprintf and related
fscanf
fgetc/fputc and related
fseek and related

Probably good to do:
readdir (compacted list showing all files for a "directory" (user versions on top of system's))
*/

#endif /* ifndef BLI_BFILE_H */