Skip to content

Commit

Permalink
update Windows version
Browse files Browse the repository at this point in the history
  • Loading branch information
tavmem committed Feb 26, 2019
1 parent 285e231 commit ba81ff1
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DEVFLAGS = -O0 -g3 -DDEBUG -Wall
OS := $(shell uname -s | tr "[:upper:]" "[:lower:]")

# Win-64
ifeq (mingw64_nt-10.0,$(OS))
ifeq (msys_nt-10.0,$(OS))
CC=gcc -DWIN32=1
PRODFLAGS += -D_FILE_OFFSET_BITS=64
LDFLAGS = -lws2_32 -static -lpthread
Expand Down
11 changes: 3 additions & 8 deletions src/0.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,11 +876,6 @@ Z K _3d_(K x,K y) {
//I n; //DO(10, if ((n = send(sockfd, buf, -1 + sizeof buf, 0)) == -1) { perror("send error"); R DOE; } else hi(OK))
}

#ifdef WIN32
#define popen _popen
#define pclose _pclose
#endif

K popen_charvec(S cmd) {
FILE *f; K z,l; S s=0; I n=0;
f=popen(cmd,"r"); P(!f,_n())
Expand Down Expand Up @@ -956,7 +951,7 @@ K _4d_(S srvr,S port,K y) {
if(INVALID_SOCKET==(sockfd=socket(ptr->ai_family,ptr->ai_socktype,ptr->ai_protocol)))continue;
else if(-1==connect(sockfd,ptr->ai_addr,ptr->ai_addrlen)){neterrno=WSAGetLastError(); r=closesocket(sockfd); if(r)R FE; continue;}
else break;
if(!ptr){fprintf(stderr, "conn: failed to connect (lld%s)\n",neterrno); freeaddrinfo(result); R DOE;}
if(!ptr){fprintf(stderr, "conn: failed to connect (%lld)\n",neterrno); freeaddrinfo(result); R DOE;}
I n=strlen(kC(y)); C msg[n+5]; for(i=0;i<n+1;i++){msg[i]=kC(y)[i];}
msg[n]='\r'; msg[n+1]='\n'; msg[n+2]='\r'; msg[n+3]='\n'; msg[n+4]='\0';
if(send(sockfd, msg, strlen(msg), 0)==-1){O("errno:%d\n",errno); r=closesocket(sockfd); if(r)R FE; freeaddrinfo(result); R WE;}
Expand Down Expand Up @@ -1044,7 +1039,7 @@ K _5d_(K x,K y,I dosync) {
I ft,fn;

#ifdef WIN32
size_t pread(int __fd,void* __buf,size_t __nbyte,off_t __off);
ssize_t pread (int __fd, void *__buf, size_t __nbytes, off_t __offset);
#endif
I g;
g=pread(f,&ft,sizeof(ft),2*sizeof(I)); if(!g)show(kerr("pread"));
Expand Down Expand Up @@ -1210,7 +1205,7 @@ K _3m(K x) {
// loop through all the results and connect to the first we can
for(p = servinfo; p != NULL; p = p->ai_next)
if(INVALID_SOCKET==(sockfd=socket(p->ai_family,p->ai_socktype,p->ai_protocol))){
O("client socket(): %ld\n", WSAGetLastError()); continue; }
O("client socket(): %d\n", WSAGetLastError()); continue; }
else if(-1==connect(sockfd, p->ai_addr, p->ai_addrlen)){
O("client connect(): %d\n", WSAGetLastError());
rv=closesocket(sockfd); if(rv)R FE; continue; }
Expand Down
4 changes: 2 additions & 2 deletions src/getline.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ I getdelim(S *s,size_t*n, I d, FILE *f)//target, current capacity, delimiter, fi
#endif

#ifdef WIN32
I getline(S *s,size_t *n, FILE *f){ R getdelim(s,n,'\n',f);}
I getdelim(S *s,size_t *n, I d, FILE *f) { //target, current capacity, delimiter, file
ssize_t getline (char **s, size_t *n, FILE *f){ R getdelim(s,n,'\n',f);}
ssize_t getdelim (char **s, size_t *n, int d, FILE *f){ //target, current capacity, delimiter, file
#if 0
// this code is MSVC runtime version specific
char *q; I w=0;
Expand Down
2 changes: 1 addition & 1 deletion src/getline.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ I getdelim(S *s,size_t * __restrict__ n,I d,FILE *f);
#endif

#if WIN32
I getdelim(S*s,size_t*n,I d,FILE *f);
ssize_t getdelim (char **, size_t *, int, FILE *);
#endif
5 changes: 2 additions & 3 deletions src/kc.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ I kinit() { //oom (return bad)
#ifndef WIN32
PG = sysconf(_SC_PAGE_SIZE);
#else
_fmode = O_BINARY;
SYSTEM_INFO si; GetSystemInfo(&si); PG = si.dwPageSize;
#endif

Expand Down Expand Up @@ -495,7 +494,7 @@ void *socket_thread(void *arg) {
if (!p) { fprintf(stderr, "server: failed to bind\n"); exit(2); }
freeaddrinfo(result);

if(SOCKET_ERROR==listen(listener, 10)){O("listen() failed with error: %ld\n", WSAGetLastError()); exit(3);}
if(SOCKET_ERROR==listen(listener, 10)){O("listen() failed with error: %d\n", WSAGetLastError()); exit(3);}
else FD_SET(listener, &master);

SOCKET SockSet[FD_SETSIZE];
Expand All @@ -511,7 +510,7 @@ void *socket_thread(void *arg) {
if(FD_ISSET(listener, &read_fds)) {
addrlen = sizeof remoteaddr;
SockSet[nxt] = accept(listener, (struct sockaddr *)&remoteaddr, &addrlen);
if(INVALID_SOCKET==SockSet[nxt]){O("accept() failed with %ld\n",WSAGetLastError()); exit(4);}
if(INVALID_SOCKET==SockSet[nxt]){O("accept() failed with %d\n",WSAGetLastError()); exit(4);}
else {
wipe_tape(nxt);
FD_SET(SockSet[nxt], &master); nfd++;
Expand Down
2 changes: 1 addition & 1 deletion src/p.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

S lineA;
S lineB;
__thread I fdc=1; // Flag denameD create
I fdc=1; // Flag denameD create
I fll=0; //flag line length

#if 0
Expand Down
14 changes: 7 additions & 7 deletions src/r.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Z S rangematch(S p,C t,S r);
#define __dvl "{x@&(#y)=y?/:x}"
#define __gtime "{(_dj _ x % 86400; 100 _sv 24 60 60 _vsx x ! 86400)}"
#define __hat "{:[(1~4:x)|(2~4:x); _f[!x;y];:[@y;_f[x;,y]; x _dvl y]]}"
#define __in "{:[@y;x~y;:[~-2=4:y;1;~x~0n;1;0n=+/y];(#y)>y?x;0]}"
#define __In "{:[@y;x~y;:[~-2=4:y;1;~x~0n;1;0n=+/y];(#y)>y?x;0]}"
#define __inv "{((2##*x)#1,&#*x)_lsq x}"
#define __lin "{{:[@y;x~y;:[~-2=4:y;1;~x~0n;1;0n=+/y];(#y)>y?x;0]}[;y]'x}"
#define __mul "{x _dot\\:y}"
Expand All @@ -104,7 +104,7 @@ S_DYAD(dvl, __dvl)
// 151013AP S_DYAD(di, "{:[@x;._f[. x;(!x)?/:y];x@&@[(#x)#1;y;:;0]]}")
S_DYAD(di, __di)
S_DYAD(dv, __dv)
S_DYAD(in, __in)
S_DYAD(in, __In)
// 151012AP S_DYAD(lin, "{_in[;y]/:x}")
//S_DYAD(lin, "{_in[;y]'x}")
S_DYAD(lin, __lin)
Expand All @@ -116,7 +116,7 @@ S_TRIAD(ssr, __ssr) //missing a few things

K kdef(I n) {
SW(n){CS(98,R X(__gtime)) CS(101,R X(__inv)) CS(107,R X(__binl)) CS(108,R X(__di)) CS(111,R X(__dv)) CS(112, R X(__dvl))
CS(113,R X(__hat)) CS(114,R X(__in)) CS(115, R X(__lin)) CS(117, R X(__mul)) CS(121, R X(__sv)) CS(123, R X(__ssr)) }
CS(113,R X(__hat)) CS(114,R X(__In)) CS(115, R X(__lin)) CS(117, R X(__mul)) CS(121, R X(__sv)) CS(123, R X(__ssr)) }
R (K)0; }

#define W(x) x
Expand Down Expand Up @@ -748,15 +748,15 @@ Z void svdcmp(F **a, I m, I n, F *w, F **v, F *t)
}

#ifdef WIN32
I setenv(cS name, cS value, I overwrite)
int setenv (const char *__string, const char *__value, int __overwrite)
{
I errcode = 0;
if(!overwrite) {
if(!__overwrite) {
size_t envsize = 0;
errcode = getenv_s(&envsize, NULL, 0, name);
errcode = getenv_s(&envsize, NULL, 0, __string);
if(errcode || envsize) R errcode;
}
R _putenv_s(name, value);
R _putenv_s(__string, __value);
}
#endif

Expand Down
8 changes: 2 additions & 6 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,9 @@ Z I tests02()
TC(1 0, ("a.c";"bc") _sm "*.[ch]")
TC_("0 1", "($`one;$`two) _sm $`two")
TC_("0 1", "`one `two _sm $`two")
#ifndef WIN32
TC_("$`xxx", "`hostname _setenv $`xxx; _getenv `hostname")
#endif
TC(".k", ."\\d a"; ."\\d .k"; $_d) // check for memory leaks
TC(1 2, a:.((`b;1);(`c;2)); `a[`b`c])
TC(3, a:1; \\b:2; c:3) // check: \b n
Expand Down Expand Up @@ -1081,15 +1083,9 @@ Z I testsBook()
TC(" abcd", 7$`abcd)
TC(" 2.35", 7.2 $ 2.345)
TC(" 714.00", 7.2 $ 714)
#ifdef WIN32
TC("1.2e-034", $ 1.2e-34)
TC("2.35e+000" , -9.2 $ 2.345)
TC("7.14e+002" , -9.2 $ 714)
#else
TC("1.2e-34", $ 1.2e-34)
TC("2.35e+00 " , -9.2 $ 2.345)
TC("7.14e+02 " , -9.2 $ 714)
#endif
TC(27, 0$"27")
TC(3.4, 0.0$"3.4")
TC(27.0 , 0.0$"27")
Expand Down
8 changes: 4 additions & 4 deletions src/win/pread.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#include <fcntl.h>
#include <unistd.h>

size_t pread(int __fd,void* __buf,size_t __nbyte,off_t __off)
ssize_t pread(int __fd,void* __buf,size_t __nbytes,off_t __offset)
{
size_t ret;
ssize_t ret;
off_t old = lseek(__fd,0,SEEK_CUR);
if(old==(off_t)-1)return -1;
if(-1==lseek(__fd,__off,SEEK_SET))return -1;
ret=read(__fd,__buf,__nbyte);
if(-1==lseek(__fd,__offset,SEEK_SET))return -1;
ret=read(__fd,__buf,__nbytes);
lseek(__fd,old,SEEK_SET);
return ret;
}

0 comments on commit ba81ff1

Please sign in to comment.