Clarify portability and main program.
[python/dscho.git] / BeOS / ar-1.1 / mwlib.h
blob67af32556c4d5ab6bb333b6876b5f012237e89cd
1 /*
2 ** mwlib.h - POSIX 1003.2 "ar" command
3 **
4 ** $Id$
5 **
6 ** This isn't a pure POSIX 1003.2 ar; it only manipulates Metrowerks
7 ** Library files, not general-purpose POSIX 1003.2 format archives.
8 **
9 ** Dec. 14, 1997 Chris Herborth (chrish@qnx.com)
11 ** This code is donated to the PUBLIC DOMAIN. You can use, abuse, modify,
12 ** redistribute, steal, or otherwise manipulate this code. No restrictions
13 ** at all. If you laugh at this code, you can't use it.
15 ** This "ar" was implemented using IEEE Std 1003.2-1992 as the basis for
16 ** the interface, and Metrowerk's published docs detailing their library
17 ** format. Look inside for clues about how reality differs from MW's
18 ** documentation on BeOS...
21 #include <support/SupportDefs.h>
22 #include <time.h>
24 /* ----------------------------------------------------------------------
25 ** Constants
28 #define MWLIB_MAGIC_WORD 'MWOB'
29 #define MWLIB_MAGIC_PROC 'PPC '
31 /* ----------------------------------------------------------------------
32 ** Structures
34 ** This is based on the "Metrowerks CodeWarrior Library Reference
35 ** Specification", which isn't 100% accurate for BeOS.
38 typedef struct MWLibHeader {
39 uint32 magicword;
40 uint32 magicproc;
41 uint32 magicflags;
42 uint32 version;
44 uint32 code_size;
45 uint32 data_size;
47 uint32 num_objects;
48 } MWLibHeader;
50 typedef struct MWLibFile {
51 time_t m_time;
53 uint32 off_filename;
54 uint32 off_fullpath;
55 uint32 off_object;
56 uint32 object_size;
57 } MWLibFile;
59 typedef struct MWLib {
60 MWLibHeader header;
62 MWLibFile *files;
64 char **names;
66 char **data;
67 } MWLib;
69 /* This bears no resemblance to what's in the Metrowerks docs.
71 ** Note that this is incomplete; this is all the info I needed for
72 ** ar though.
74 typedef struct MWObject {
75 uint32 magic_word; /* 'MWOB' */
76 uint32 arch; /* 'PPC '; this isn't in the docs */
77 uint32 version;
78 uint32 flags;
80 uint32 code_size;
81 uint32 data_size;
82 } MWObject;
84 /* ----------------------------------------------------------------------
85 ** Function prototypes
87 ** load_MW_lib() - load a Metrowerks library
89 ** Returns:
90 ** B_OK - all is well
91 ** B_FILE_NOT_FOUND - can't open the given file
92 ** B_IO_ERROR - can't read from the given file
93 ** B_BAD_VALUE - invalid magic word in the file
94 ** B_MISMATCHED_VALUES - invalid processor value (ie, not a PowerPC lib),
95 ** or the magicflags member is not 0, or the file
96 ** version number isn't 1.
97 ** B_NO_MEMORY - unable to allocate memory while loading the lib
99 ** write_MW_lib() - write a Metrowerks library
101 ** Returns:
102 ** B_OK - all is well
104 ** write_MW_lib() - write a Metrowerks library file
106 ** Returns:
107 ** B_OK - all is well; doesn't necessarily mean the file was written
108 ** properly, just that you didn't lose any data
109 ** B_NO_MEMORY - unable to allocate offset buffers
110 ** B_ERROR - problem with backup file (can't rename existing file)
112 ** Note:
113 ** If you use this in a long-lived program, it leaks memory; the MWLib
114 ** contents are never free()'d.
116 status_t load_MW_lib( MWLib *lib, const char *filename );
117 status_t write_MW_lib( MWLib *lib, const char *filename );
118 void setfiletype( const char *filename, const char *type );