Macros | Functions | Variables
mod_lib.cc File Reference
#include <kernel/mod2.h>
#include <resources/feFopen.h>
#include <reporter/reporter.h>
#include <polys/mod_raw.h>
#include <Singular/mod_lib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/stat.h>
#include <errno.h>

Go to the source code of this file.

Macros

#define SI_BUILTIN_LIBSTR(name)   (char*) #name ".so",
 
#define BYTES_TO_CHECK   7
 

Functions

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

Variables

const char *const si_builtin_libs [] = { SI_FOREACH_BUILTIN(SI_BUILTIN_LIBSTR) NULL }
 

Macro Definition Documentation

§ BYTES_TO_CHECK

#define BYTES_TO_CHECK   7

Definition at line 22 of file mod_lib.cc.

§ SI_BUILTIN_LIBSTR

#define SI_BUILTIN_LIBSTR (   name)    (char*) #name ".so",

Definition at line 16 of file mod_lib.cc.

Function Documentation

§ type_of_LIB()

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

Definition at line 24 of file mod_lib.cc.

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

Variable Documentation

§ si_builtin_libs

const char* const si_builtin_libs[] = { SI_FOREACH_BUILTIN(SI_BUILTIN_LIBSTR) NULL }

Definition at line 18 of file mod_lib.cc.