diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2024-08-25 16:55:24 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2024-08-25 16:55:24 (GMT) |
commit | 41dcf8a45d61108fef1f545ecdee5d79d8135089 (patch) | |
tree | 358c8a9b85e3d582ebe8e0f68c208785a4801517 /src/common/szbin.h | |
parent | f505830e800e4061d6e57c2b0769f956e70a2d84 (diff) |
Restore an improved cURL support.
Diffstat (limited to 'src/common/szbin.h')
-rw-r--r-- | src/common/szbin.h | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/common/szbin.h b/src/common/szbin.h new file mode 100644 index 0000000..ac938ab --- /dev/null +++ b/src/common/szbin.h @@ -0,0 +1,88 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * szbin.h - prototypes pour une manipulation de données accompagnées d'une taille + * + * Copyright (C) 2024 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide 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 3 of the License, or + * (at your option) any later version. + * + * Chrysalide 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _COMMON_SZBIN_H +#define _COMMON_SZBIN_H + + +#include <malloc.h> +#include <string.h> + + + +/* Structure associant données et taille */ +typedef struct _sized_binary_t +{ + union { + + const char *static_data; /* Données non modifiées */ + char *data; /* Chaîne de caractères */ + + }; + + size_t size; /* Taille correspondante */ + +} sized_binary_t; + + +#define init_sized_binary(sb) \ + do \ + { \ + (sb)->data = NULL; \ + (sb)->size = 0; \ + } \ + while (0) + + +#define setup_sized_binary(sb, s) \ + do \ + { \ + (sb)->data = malloc(s); \ + (sb)->size = s; \ + } \ + while (0) + + +#define dup_into_sized_binary(sb, d, s) \ + do \ + { \ + setup_sized_binary(sb, s); \ + memcpy((sb)->data, d, s); \ + } \ + while (0) + + +#define exit_sized_binary(sb) \ + do \ + { \ + if ((sb)->data != NULL) \ + { \ + free((sb)->data); \ + init_sized_binary(sb); \ + } \ + } \ + while (0) + + + +#endif /* _COMMON_SZBIN_H */ |