2024-08-30 02:35:17 +00:00
|
|
|
// ISC License
|
2024-09-01 06:11:57 +00:00
|
|
|
//
|
2024-08-30 02:35:17 +00:00
|
|
|
// Copyright (c) 2024 Stephen Seo
|
2024-09-01 06:11:57 +00:00
|
|
|
//
|
2024-08-30 02:35:17 +00:00
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
2024-09-01 06:11:57 +00:00
|
|
|
//
|
2024-08-30 02:35:17 +00:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
// PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
//
|
|
|
|
// `archiver.h` is the header for an interface to creating an archive file.
|
2024-07-16 07:16:58 +00:00
|
|
|
|
|
|
|
#ifndef SEODISPARATE_COM_SIMPLE_ARCHIVER_ARCHIVER_H_
|
|
|
|
#define SEODISPARATE_COM_SIMPLE_ARCHIVER_ARCHIVER_H_
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2024-07-24 05:03:03 +00:00
|
|
|
#include "data_structures/hash_map.h"
|
2024-07-16 07:16:58 +00:00
|
|
|
#include "data_structures/linked_list.h"
|
|
|
|
#include "parser.h"
|
|
|
|
|
|
|
|
typedef struct SDArchiverState {
|
|
|
|
/*
|
|
|
|
*/
|
|
|
|
unsigned int flags;
|
|
|
|
const SDArchiverParsed *parsed;
|
|
|
|
FILE *out_f;
|
2024-07-24 05:05:05 +00:00
|
|
|
SDArchiverHashMap *map;
|
2024-09-06 05:23:27 +00:00
|
|
|
size_t count;
|
|
|
|
size_t max;
|
|
|
|
size_t digits;
|
2024-07-16 07:16:58 +00:00
|
|
|
} SDArchiverState;
|
|
|
|
|
|
|
|
enum SDArchiverStateReturns {
|
|
|
|
SDAS_SUCCESS = 0,
|
|
|
|
SDAS_HEADER_ALREADY_WRITTEN = 1,
|
|
|
|
SDAS_FAILED_TO_WRITE,
|
|
|
|
SDAS_NO_COMPRESSOR,
|
|
|
|
SDAS_NO_DECOMPRESSOR,
|
2024-07-17 04:30:05 +00:00
|
|
|
SDAS_INVALID_PARSED_STATE,
|
2024-07-18 05:39:01 +00:00
|
|
|
SDAS_INVALID_FILE,
|
2024-07-24 05:05:05 +00:00
|
|
|
SDAS_INTERNAL_ERROR,
|
2024-07-24 05:52:35 +00:00
|
|
|
SDAS_FAILED_TO_CREATE_MAP,
|
2024-07-26 03:39:56 +00:00
|
|
|
SDAS_FAILED_TO_EXTRACT_SYMLINK,
|
|
|
|
SDAS_FAILED_TO_CHANGE_CWD
|
2024-07-16 07:16:58 +00:00
|
|
|
};
|
|
|
|
|
2024-07-18 05:39:01 +00:00
|
|
|
/// Returned pointer must not be freed.
|
|
|
|
char *simple_archiver_error_to_string(enum SDArchiverStateReturns error);
|
|
|
|
|
2024-07-16 07:16:58 +00:00
|
|
|
SDArchiverState *simple_archiver_init_state(const SDArchiverParsed *parsed);
|
|
|
|
void simple_archiver_free_state(SDArchiverState **state);
|
|
|
|
|
|
|
|
/// Returns zero on success. Otherwise one value from SDArchiverStateReturns
|
|
|
|
/// enum.
|
|
|
|
int simple_archiver_write_all(FILE *out_f, SDArchiverState *state,
|
|
|
|
const SDArchiverLinkedList *filenames);
|
|
|
|
|
2024-07-17 04:30:05 +00:00
|
|
|
/// Returns zero on success.
|
2024-07-18 04:16:24 +00:00
|
|
|
int simple_archiver_parse_archive_info(FILE *in_f, int do_extract,
|
|
|
|
const SDArchiverState *state);
|
2024-07-17 04:30:05 +00:00
|
|
|
|
2024-07-17 05:32:39 +00:00
|
|
|
/// Returns zero on success.
|
2024-07-17 07:37:32 +00:00
|
|
|
int simple_archiver_de_compress(int pipe_fd_in[2], int pipe_fd_out[2],
|
2024-07-17 10:00:34 +00:00
|
|
|
const char *cmd, void *pid_out);
|
2024-07-17 05:32:39 +00:00
|
|
|
|
2024-07-16 07:16:58 +00:00
|
|
|
#endif
|