My Project  debian-1:4.1.2-p1+ds-2
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 22 of file mod_lib.cc.

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