summaryrefslogtreecommitdiff
path: root/core/src/xmake/binutils/mslib/prefix.h
blob: 521755fb2fb627f77a3a1723ac2f3ba6d659bb4f (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
/*!A cross-platform build utility based on Lua
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Copyright (C) 2015-present, Xmake Open Source Community.
 *
 * @author      ruki
 * @file        prefix.h
 *
 */
#ifndef XM_BINUTILS_MSLIB_PREFIX_H
#define XM_BINUTILS_MSLIB_PREFIX_H

/* //////////////////////////////////////////////////////////////////////////////////////
 * includes
 */
#include "../prefix.h"

/* //////////////////////////////////////////////////////////////////////////////////////
 * types
 */

// MSVC lib header
#include "tbox/prefix/packed.h"
typedef struct __xm_mslib_header_t {
    tb_char_t   name[16];
    tb_char_t   date[12];
    tb_char_t   uid[6];
    tb_char_t   gid[6];
    tb_char_t   mode[8];
    tb_char_t   size[10];
    tb_char_t   fmag[2];
} __tb_packed__ xm_mslib_header_t;
#include "tbox/prefix/packed.h"

/* //////////////////////////////////////////////////////////////////////////////////////
 * interfaces
 */

static __tb_inline__ tb_int64_t xm_binutils_mslib_parse_decimal(tb_char_t const *p, tb_size_t n) {
    tb_assert_and_check_return_val(p && n > 0, -1);
    tb_int64_t v = 0;
    tb_char_t const* e = p + n;
    while (p < e && *p == ' ') {
        p++;
    }
    while (p < e && *p >= '0' && *p <= '9') {
        v = v * 10 + (*p - '0');
        p++;
    }
    return v;
}

static __tb_inline__ tb_bool_t xm_binutils_mslib_check_magic(tb_stream_ref_t istream) {
    tb_char_t magic[8];
    if (!tb_stream_bread(istream, (tb_byte_t*)magic, 8)) {
        return tb_false;
    }
    return tb_strncmp(magic, "!<arch>\n", 8) == 0;
}

#endif