116
117
* Write-support will extend => zzip_closedir with semantics to finalize the
117
118
* zip-archive by writing the zip-trailer and closing the archive file.
120
zzip_dir_creat_ext_io(zzip_char_t* name, int o_mode,
121
zzip_strings_t* ext, zzip_plugin_io_t io)
121
zzip_dir_creat_ext_io(zzip_char_t * name, int o_mode,
122
zzip_strings_t * ext, zzip_plugin_io_t io)
123
if (! io) io = zzip_get_default_io ();
125
io = zzip_get_default_io();
125
127
if (io != zzip_get_default_io())
126
{ /* the current io-structure does not contain a "write" entry,
127
* and therefore this parameter is useless. Anyone to expect
128
* some behavior should be warned, so here we let the function
129
* fail bluntly - and leaving the recovery to the application
129
/* the current io-structure does not contain a "write" entry,
130
* and therefore this parameter is useless. Anyone to expect
131
* some behavior should be warned, so here we let the function
132
* fail bluntly - and leaving the recovery to the application
137
{ /* not implemented - however, we respect that a null argument to
138
* zzip_mkdir and zzip_creat works, so we silently still do the mkdir
140
if (! _mkdir (name, o_mode) || errno == EEXIST)
141
/* not implemented - however, we respect that a null argument to
142
* zzip_mkdir and zzip_creat works, so we silently still do the mkdir
144
if (! _mkdir(name, o_mode) || errno == EEXIST)
144
149
# define MAX_EXT_LEN 10
145
ZZIP_DIR* dir = zzip_dir_alloc (ext);
150
ZZIP_DIR *dir = zzip_dir_alloc(ext);
146
151
int name_len = strlen(name);
147
dir->realname = malloc (name_len+MAX_EXT_LEN);
148
if (! dir->realname) goto error;
150
memcpy (dir->realname, name, name_len+1);
151
___ int fd = __zzip_try_open (
152
dir->realname, O_EXCL|O_TRUNC|O_WRONLY, ext, io);
153
if (fd != -1) { dir->fd = fd; return dir; }
155
___ zzip_strings_t* exx = ext; int exx_len;
152
dir->realname = malloc(name_len + MAX_EXT_LEN);
156
memcpy(dir->realname, name, name_len + 1);
158
__zzip_try_open(dir->realname, O_EXCL | O_TRUNC | O_WRONLY, ext,
161
{ dir->fd = fd; return dir; }
163
___ zzip_strings_t *exx = ext;
158
if ((exx_len = strlen (*exx)+1) <= name_len &&
159
! memcmp (dir->realname+(name_len-exx_len), *exx, exx_len))
160
break; /* keep unmodified */
161
exx++; if (*exx) continue;
167
if ((exx_len = strlen(*exx) + 1) <= name_len &&
168
! memcmp(dir->realname + (name_len - exx_len), *exx, exx_len))
169
break; /* keep unmodified */
163
if (! (exx_len = strlen (*exx)) || exx_len >= MAX_EXT_LEN) break;
164
memcpy (dir->realname+name_len, exx, exx_len); /* append! */
166
fd = io->fd.open (dir->realname, O_CREAT|O_TRUNC|O_WRONLY, o_mode);
174
if (! (exx_len = strlen(*exx)) || exx_len >= MAX_EXT_LEN)
176
memcpy(dir->realname + name_len, exx, exx_len); /* append! */
179
fd = io->fd.open(dir->realname, O_CREAT | O_TRUNC | O_WRONLY, o_mode);
167
180
dir->realname[name_len] = '\0'; /* keep ummodified */
168
if (fd != -1) { dir->fd = fd; return dir; }
170
zzip_dir_free (dir); return 0;
182
{ dir->fd = fd; return dir; }
203
218
* EEXIST errors from => mkdir(2) are suppressed. (fixme: delete the
204
219
* given subtree? like suggested by O_TRUNC? not done so far!)
207
zzip_createdir(zzip_char_t* name, int o_mode)
222
zzip_createdir(zzip_char_t * name, int o_mode)
209
224
if (o_mode & S_IWGRP)
211
if (-1 == _mkdir(name, o_mode) && errno != EEXIST) /* fail */
226
if (-1 == _mkdir(name, o_mode) && errno != EEXIST) /* fail */
213
return zzip_opendir (name);
228
return zzip_opendir(name);
215
return zzip_dir_creat (name, o_mode);
230
return zzip_dir_creat(name, o_mode);
218
233
/** => zzip_file_creat also: mkdir(2), creat(2), zzip_dir_creat
304
321
* using => zlib(3) and appended to the zip archive file.
307
zzip_write(ZZIP_FILE* file, const void* ptr, zzip_size_t len)
324
zzip_write(ZZIP_FILE * file, const void *ptr, zzip_size_t len)
309
326
if (zzip_file_real(file))
310
return write (zzip_realfd (file), ptr, len);
327
return write(zzip_realfd(file), ptr, len);
312
return zzip_file_write (file, ptr, len);
329
return zzip_file_write(file, ptr, len);
315
332
/** => zzip_write also: zzip_file_creat
348
366
* the (still-open) ZZIP_DIR handle.
351
zzip_fwrite(const void* ptr, zzip_size_t len, zzip_size_t multiply,
369
zzip_fwrite(const void *ptr, zzip_size_t len, zzip_size_t multiply,
354
zzip_ssize_t value = zzip_write (file, ptr, len * multiply);
372
zzip_ssize_t value = zzip_write(file, ptr, len * multiply);
357
375
return (zzip_size_t) value;
360
#if 0 /* pure documentation */
378
#if 0 /* pure documentation */
361
380
/** create a zipped file/directory also: zzip_dir_creat, mkdir(2)
363
382
* This function creates a directory entry in the default zip-archive.
398
418
#define zzip_creat(name,mode) \ -
399
419
zzip_file_creat(zzip_savefile,name,mode)
402
zzip_creat(zzip_char_t* name, int o_mode)
422
zzip_creat(zzip_char_t * name, int o_mode)
404
424
return zzip_file_creat(zzip_savefile, name, mode);
409
#if 0 /* pure documentation */
429
#if 0 /* pure documentation */
410
431
/** start writing to the magic zzip_savefile also: zzip_creat, zzip_write
412
433
* open a zip archive for writing via the magic zzip_savefile macro
431
452
* on the real filesystem.
434
zzip_mkfifo(zzip_char_t* name, int o_mode)
436
if (zzip_savefile) zzip_closedir (zzip_savefile);
455
zzip_mkfifo(zzip_char_t * name, int o_mode)
458
zzip_closedir(zzip_savefile);
437
459
zzip_savefile = zzip_createdir(name, o_mode);
441
#if 0 /* pure documentation */
463
#if 0 /* pure documentation */
442
465
/** => zzip_mkfifo also: zzip_closedir, sync(2)
444
467
* finalize a zip archive thereby writing the central directory to