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

#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.

#define SI_MOD_INIT0 (   name)    name##_mod_init

Definition at line 4 of file mod_lib.h.

Function Documentation

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

Definition at line 23 of file mod_lib.cc.

24 {
25  const unsigned char mach_o[]={0xfe,0xed,0xfa,0xce,0};
26  const unsigned char mach_O[]={0xce,0xfa,0xed,0xfe,0};
27 
28  const unsigned char mach_o64[]={0xfe,0xed,0xfa,0xcf,0};
29  const unsigned char mach_O64[]={0xcf,0xfa,0xed,0xfe,0};
30 
31  const unsigned char mach_FAT[]={0xca,0xfe,0xba,0xbe,0};
32  const unsigned char mach_fat[]={0xbe,0xba,0xfe,0xca,0};
33 
34  int i=0;
35  while(si_builtin_libs[i]!=NULL)
36  {
37  if (strcmp(newlib,si_builtin_libs[i])==0)
38  {
39  if(libnamebuf!=NULL) strcpy(libnamebuf,newlib);
40  return LT_BUILTIN;
41  }
42  i++;
43  }
44  char buf[BYTES_TO_CHECK+1]; /* one extra for terminating '\0' */
45  struct stat sb;
46  int nbytes = 0;
47  int ret;
48  lib_types LT=LT_NONE;
49 
50  FILE * fp = feFopen( newlib, "r", libnamebuf, FALSE );
51 
52  do
53  {
54  ret = stat(libnamebuf, &sb);
55  } while((ret < 0) and (errno == EINTR));
56 
57  if (fp==NULL)
58  {
59  return LT_NOTFOUND;
60  }
61  if((sb.st_mode & S_IFMT) != S_IFREG)
62  {
63  goto lib_type_end;
64  }
65  if ((nbytes = fread((char *)buf, sizeof(char), BYTES_TO_CHECK, fp)) == -1)
66  {
67  goto lib_type_end;
68  /*NOTREACHED*/
69  }
70  if (nbytes == 0)
71  goto lib_type_end;
72  else
73  {
74  buf[nbytes++] = '\0'; /* null-terminate it */
75  }
76  if( (strncmp(buf, "\177ELF", 4)==0)) /* generic ELF */
77  {
78  LT = LT_ELF;
79  //omFree(newlib);
80  //newlib = omStrDup(libnamebuf);
81  goto lib_type_end;
82  }
83 
84  if( (strncmp(buf, (const char *)mach_o, 4)==0) || (strncmp(buf, (const char *)mach_O, 4)==0)) /* generic Mach-O module */
85  {
86  LT = LT_MACH_O;
87  //omFree(newlib);
88  //newlib = omStrDup(libnamebuf);
89  goto lib_type_end;
90  }
91 
92  if( (strncmp(buf, (const char *)mach_o64, 4)==0) || (strncmp(buf, (const char *)mach_O64, 4)==0)) /* generic Mach-O 64-bit module */
93  {
94  LT = LT_MACH_O;
95  //omFree(newlib);
96  //newlib = omStrDup(libnamebuf);
97  goto lib_type_end;
98  }
99 
100  if( (strncmp(buf, (const char *)mach_FAT, 4)==0) || (strncmp(buf, (const char *)mach_fat, 4)==0)) /* generic Mach-O fat universal module */
101  {
102  LT = LT_MACH_O;
103  //omFree(newlib);
104  //newlib = omStrDup(libnamebuf);
105  goto lib_type_end;
106  }
107 
108  if( (strncmp(buf, "\02\020\01\016\05\022@", 7)==0))
109  {
110  LT = LT_HPUX;
111  //omFree(newlib);
112  //newlib = omStrDup(libnamebuf);
113  goto lib_type_end;
114  }
115  if(isprint(buf[0]) || buf[0]=='\n')
116  { LT = LT_SINGULAR; goto lib_type_end; }
117 
118  lib_type_end:
119  fclose(fp);
120  return LT;
121 }
CanonicalForm fp
Definition: cfModGcd.cc:4043
const char *const si_builtin_libs[]
Definition: mod_lib.cc:17
#define FALSE
Definition: auxiliary.h:140
#define BYTES_TO_CHECK
Definition: mod_lib.cc:21
Definition: mod_raw.h:16
int status int void * buf
Definition: si_signals.h:58
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:46
int i
Definition: cfEzgcd.cc:123
lib_types
Definition: mod_raw.h:16
#define NULL
Definition: omList.c:10
char libnamebuf[128]
Definition: libparse.cc:1096