=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/builtin/file.c,v retrieving revision 1.26 retrieving revision 1.35 diff -u -p -r1.26 -r1.35 --- OpenXM_contrib2/asir2000/builtin/file.c 2008/11/19 13:12:43 1.26 +++ OpenXM_contrib2/asir2000/builtin/file.c 2017/06/10 05:32:24 1.35 @@ -45,28 +45,31 @@ * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. * - * $OpenXM: OpenXM_contrib2/asir2000/builtin/file.c,v 1.25 2008/11/18 09:17:31 ohara Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/builtin/file.c,v 1.34 2015/08/14 13:51:54 fujimoto Exp $ */ #include "ca.h" #include "parse.h" #include "ox.h" #include "base.h" -#if !defined(VISUAL) +#if !defined(VISUAL) && !defined(__MINGW32__) #include "unistd.h" #endif #if defined(PARI) #include "genpari.h" #endif -#if defined(VISUAL) +#if defined(VISUAL) || defined(__MINGW32__) #include #include #include /* #define ECGEN_KEYNAME "SoftWare\\Fujitsu\\WinECgen\\1.00.000" */ #define ECGEN_KEYNAME "SoftWare\\Fujitsu\\FSEcParamGen\\V1.0L10" #define ASIR_KEYNAME "SoftWare\\Fujitsu\\Asir\\1999.03.31" +#define R_OK 0x04 #endif +void Psprintf(NODE,STRING *); + void Pget_rootdir(); void Paccess(),Premove_file(); void Pbsave_enc(), Pbload_enc(); @@ -80,6 +83,7 @@ void Pput_word(), Pget_word(); void Ppurge_stdin(); void Pfprintf(); void Pimport(); +void Pgetpid(); extern int des_encryption; extern char *asir_libdir; @@ -104,7 +108,7 @@ struct ftab file_tab[] = { {"bsave",Pbsave,2}, {"bload",Pbload,1}, {"get_rootdir",Pget_rootdir,0}, -#if defined(VISUAL) && defined(DES_ENC) +#if defined(DES_ENC) {"bsave_enc",Pbsave_enc,2}, {"bload_enc",Pbload_enc,1}, #endif @@ -113,6 +117,7 @@ struct ftab file_tab[] = { {"bload_compat",Pbload_compat,1}, {"bsave_cmo",Pbsave_cmo,2}, {"bload_cmo",Pbload_cmo,1}, + {"getpid",Pgetpid,0}, {0,0,0}, }; @@ -166,7 +171,7 @@ void Popen_file(NODE arg,Q *rp) asir_assert(ARG1(arg),O_STR,"open_file"); fp = fopen(name,BDY((STRING)ARG1(arg))); } else - fp = fopen(name,"r"); + fp = fopen(name,"rb"); } if ( !fp ) { sprintf(errbuf,"open_file : cannot open \"%s\"",name); @@ -503,7 +508,7 @@ void Pbload_cmo(NODE arg,Obj *rp) static struct oSTRING rootdir; -#if defined(VISUAL) +#if defined(VISUAL) || defined(__MINGW32__) void get_rootdir(char *name,int len) { LONG ret; @@ -515,11 +520,11 @@ void get_rootdir(char *name,int len) strcpy(name,rootdir.body); return; } - - if ( access("UseCurrentDir",0) >= 0 ) { - GetCurrentDirectory(BUFSIZ,name); + if ( GetModuleFileName(NULL,name,BUFSIZ) ) { slash = strrchr(name,'\\'); - if ( slash ) + *slash = 0; + slash = strrchr(name,'\\'); + if ( slash ) *slash = 0; return; } @@ -582,7 +587,19 @@ void Pget_rootdir(STRING *rp) *rp = &rootdir; } -#if defined(VISUAL) && defined(DES_ENC) +void Pgetpid(Q *rp) +{ + int id; + +#if defined(VISUAL) || defined(__MINGW32__) + id = GetCurrentProcessId(); +#else + id = getpid(); +#endif + STOQ(id,*rp); +} + +#if defined(DES_ENC) void Pbsave_enc(NODE arg,Obj *rp) { init_deskey(); @@ -678,17 +695,13 @@ void Premove_file(NODE arg,Q *rp) void Paccess(NODE arg,Q *rp) { -#if defined(VISUAL) - if ( access(BDY((STRING)ARG0(arg)),04) >= 0 ) -#else if ( access(BDY((STRING)ARG0(arg)),R_OK) >= 0 ) -#endif *rp = ONE; else *rp = 0; } -#if defined(VISUAL) +#if defined(VISUAL) || defined(__MINGW32__) int process_id() { return GetCurrentProcessId();