My Project
Loading...
Searching...
No Matches
Macros | Functions
mod_lib.h File Reference
#include "kernel/mod2.h"
#include "polys/mod_raw.h"

Go to the source code of this file.

Macros

#define SI_MOD_INIT0(name)   name##_mod_init
 
#define SI_FOREACH_BUILTIN(add)   SI_BUILTINMODULES_ADD(add)
 Data for type_of_LIB to determine built-in modules, use add(name) to add built-in library to macro. More...
 

Functions

lib_types type_of_LIB (const char *newlib, char *fullname)
 

Macro Definition Documentation

◆ SI_FOREACH_BUILTIN

#define SI_FOREACH_BUILTIN (   add)    SI_BUILTINMODULES_ADD(add)

Data for type_of_LIB to determine built-in modules, use add(name) to add built-in library to macro.

Definition at line 17 of file mod_lib.h.

◆ SI_MOD_INIT0

#define SI_MOD_INIT0 (   name)    name##_mod_init

Definition at line 4 of file mod_lib.h.

Function Documentation

◆ type_of_LIB()

lib_types type_of_LIB ( const char *  newlib,
char *  fullname 
)

Definition at line 27 of file mod_lib.cc.

28{
29 const unsigned char mach_o[]={0xfe,0xed,0xfa,0xce,0};
30 const unsigned char mach_O[]={0xce,0xfa,0xed,0xfe,0};
31
32 const unsigned char mach_o64[]={0xfe,0xed,0xfa,0xcf,0};
33 const unsigned char mach_O64[]={0xcf,0xfa,0xed,0xfe,0};
34
35 const unsigned char mach_FAT[]={0xca,0xfe,0xba,0xbe,0};
36 const unsigned char mach_fat[]={0xbe,0xba,0xfe,0xca,0};
37
38 const unsigned char utf16be[]={0xfe,0xff,0};
39 const unsigned char utf16le[]={0xff,0xfe,0};
40 const unsigned char utf8ms[]={0xEF,0xBB,0xBF,0};
41
42 const unsigned char dll[]={'M','Z',0};
43 int i=0;
44 while(si_builtin_libs[i]!=NULL)
45 {
46 if (strcmp(newlib,si_builtin_libs[i])==0)
47 {
48 if(libnamebuf!=NULL) strcpy(libnamebuf,newlib);
49 return LT_BUILTIN;
50 }
51 i++;
52 }
53 char buf[BYTES_TO_CHECK+1]; /* one extra for terminating '\0' */
54 struct stat sb;
55 int nbytes = 0;
56 int ret;
58
59 FILE * fp = feFopen( newlib, "r", libnamebuf, FALSE );
60
61 do
62 {
63 ret = stat(libnamebuf, &sb);
64 } while((ret < 0) and (errno == EINTR));
65
66 if (fp==NULL)
67 {
68 return LT_NOTFOUND;
69 }
70 if((sb.st_mode & S_IFMT) != S_IFREG)
71 {
72 goto lib_type_end;
73 }
74 if ((nbytes = fread((char *)buf, sizeof(char), BYTES_TO_CHECK, fp)) == -1)
75 {
76 goto lib_type_end;
77 /*NOTREACHED*/
78 }
79 if (nbytes == 0)
80 goto lib_type_end;
81 else
82 {
83 buf[nbytes++] = '\0'; /* null-terminate it */
84 }
85 if( (strncmp(buf, "\177ELF", 4)==0)) /* generic ELF */
86 {
87 LT = LT_ELF;
88 //omFree(newlib);
89 //newlib = omStrDup(libnamebuf);
90 goto lib_type_end;
91 }
92
93 if( (strncmp(buf, (const char *)mach_o, 4)==0) || (strncmp(buf, (const char *)mach_O, 4)==0)) /* generic Mach-O module */
94 {
95 LT = LT_MACH_O;
96 //omFree(newlib);
97 //newlib = omStrDup(libnamebuf);
98 goto lib_type_end;
99 }
100
101 if( (strncmp(buf, (const char *)mach_o64, 4)==0) || (strncmp(buf, (const char *)mach_O64, 4)==0)) /* generic Mach-O 64-bit module */
102 {
103 LT = LT_MACH_O;
104 //omFree(newlib);
105 //newlib = omStrDup(libnamebuf);
106 goto lib_type_end;
107 }
108
109 if( (strncmp(buf, (const char *)mach_FAT, 4)==0) || (strncmp(buf, (const char *)mach_fat, 4)==0)) /* generic Mach-O fat universal module */
110 {
111 LT = LT_MACH_O;
112 //omFree(newlib);
113 //newlib = omStrDup(libnamebuf);
114 goto lib_type_end;
115 }
116
117 if( (strncmp(buf, "\02\020\01\016\05\022@", 7)==0))
118 {
119 LT = LT_HPUX;
120 //omFree(newlib);
121 //newlib = omStrDup(libnamebuf);
122 goto lib_type_end;
123 }
124 if ((strncmp(buf,(const char *)utf16be,2)==0)
125 ||(strncmp(buf,(const char *)utf16le,2)==0))
126 {
127 WerrorS("UTF-16 not supported");
128 LT=LT_NOTFOUND;
129 goto lib_type_end;
130 }
131 if (strncmp(buf,(const char *)utf8ms,3)==0)
132 {
133 WarnS("UTF-8 detected - may not work");
134 LT=LT_SINGULAR;
135 goto lib_type_end;
136 }
137 if (strncmp(buf,(const char *)dll,2)==0)
138 {
139 LT=LT_DLL;
140 goto lib_type_end;
141 }
142 if(isprint(buf[0]) || buf[0]=='\n')
143 { LT = LT_SINGULAR; goto lib_type_end; }
144
145 lib_type_end:
146 fclose(fp);
147 return LT;
148}
#define FALSE
Definition: auxiliary.h:96
int i
Definition: cfEzgcd.cc:132
CanonicalForm fp
Definition: cfModGcd.cc:4102
#define WarnS
Definition: emacs.cc:78
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:47
void WerrorS(const char *s)
Definition: feFopen.cc:24
VAR char libnamebuf[1024]
Definition: libparse.cc:1098
const char *const si_builtin_libs[]
Definition: mod_lib.cc:16
#define BYTES_TO_CHECK
Definition: mod_lib.cc:25
lib_types
Definition: mod_raw.h:16
@ LT_MACH_O
Definition: mod_raw.h:16
@ LT_HPUX
Definition: mod_raw.h:16
@ LT_DLL
Definition: mod_raw.h:16
@ LT_SINGULAR
Definition: mod_raw.h:16
@ LT_BUILTIN
Definition: mod_raw.h:16
@ LT_ELF
Definition: mod_raw.h:16
@ LT_NONE
Definition: mod_raw.h:16
@ LT_NOTFOUND
Definition: mod_raw.h:16
#define NULL
Definition: omList.c:12
int status int void * buf
Definition: si_signals.h:59