]> git.donarmstrong.com Git - samtools.git/commitdiff
* samtools-0.1.6-9 (r470)
authorHeng Li <lh3@live.co.uk>
Tue, 29 Sep 2009 19:01:27 +0000 (19:01 +0000)
committerHeng Li <lh3@live.co.uk>
Tue, 29 Sep 2009 19:01:27 +0000 (19:01 +0000)
 * make knetfile.c compatible with MinGW (thank Martin Morgan for the patch)

Makefile.mingw
bamtk.c
knetfile.c
knetfile.h

index 80e8009d17baf955252b27935323f53d0a6c2d55..eb6ed47270ccf8fdda2650866feaea3f79887e9d 100644 (file)
@@ -1,7 +1,7 @@
 CC=                    gcc.exe
 AR=                    ar.exe
 CFLAGS=                -g -Wall -O2
-DFLAGS=                -D_FILE_OFFSET_BITS=64 -D_CURSES_LIB=2 -D_USE_KNETFILE
+DFLAGS=                -D_CURSES_LIB=2 -D_USE_KNETFILE
 LOBJS=         bgzf.o kstring.o bam_aux.o bam.o bam_import.o sam.o bam_index.o \
                        bam_pileup.o bam_lpileup.o bam_md.o glf.o razf.o faidx.o bam_sort.o \
                        knetfile.o
diff --git a/bamtk.c b/bamtk.c
index ae8f607bbf86475d260cf90e8d1bea3ce592dbc0..74deac7de55761d0afec00020fb84960398caac6 100644 (file)
--- a/bamtk.c
+++ b/bamtk.c
@@ -9,7 +9,7 @@
 #endif
 
 #ifndef PACKAGE_VERSION
-#define PACKAGE_VERSION "0.1.6-8 (r469)"
+#define PACKAGE_VERSION "0.1.6-9 (r470)"
 #endif
 
 int bam_taf2baf(int argc, char *argv[]);
index 4a41e6576c534abd8b0384ed6e55569d38dc6f50..0dee408c2255f8330bccbd9a1f58565b0ebd0cdb 100644 (file)
@@ -71,7 +71,14 @@ static int socket_wait(int fd, int is_read)
        if (is_read) fdr = &fds;
        else fdw = &fds;
        ret = select(fd+1, fdr, fdw, 0, &tv);
+#ifndef _WIN32
        if (ret == -1) perror("select");
+#else
+       if (ret == 0)
+               fprintf(stderr, "select time-out\n");
+       else if (ret == SOCKET_ERROR)
+               fprintf(stderr, "select: %d\n", WSAGetLastError());
+#endif
        return ret;
 }
 
@@ -104,16 +111,28 @@ static int socket_connect(const char *host, const char *port)
 }
 #else
 /* MinGW's printf has problem with "%lld" */
-char *uint64tostr(char *buf, uint64_t x)
+char *int64tostr(char *buf, int64_t x)
 {
-       int i, cnt;
-       for (i = 0; x; x /= 10) buf[i++] = '0' + x%10;
+       int cnt;
+       int i = 0;
+       do {
+               buf[i++] = '0' + x % 10;
+               x /= 10;
+       } while (x);
        buf[i] = 0;
        for (cnt = i, i = 0; i < cnt/2; ++i) {
                int c = buf[i]; buf[i] = buf[cnt-i-1]; buf[cnt-i-1] = c;
        }
        return buf;
 }
+
+int64_t strtoint64(const char *buf)
+{
+       int64_t x;
+       for (x = 0; *buf != '\0'; ++buf)
+               x = x * 10 + ((int64_t) *buf - 48);
+       return x;
+}
 /* In windows, the first thing is to establish the TCP connection. */
 int knet_win32_init()
 {
@@ -130,7 +149,11 @@ void knet_win32_destroy()
  * non-Windows OS, I do not use this one. */
 static SOCKET socket_connect(const char *host, const char *port)
 {
-#define __err_connect(func) do { perror(func); return -1; } while (0)
+#define __err_connect(func)                                                                            \
+       do {                                                                                                            \
+               fprintf(stderr, "%s: %d\n", func, WSAGetLastError());   \
+               return -1;                                                                                              \
+       } while (0)
 
        int on = 1;
        SOCKET fd;
@@ -183,7 +206,11 @@ static off_t my_netread(int fd, void *buf, off_t len)
 
 static int kftp_get_response(knetFile *ftp)
 {
+#ifndef _WIN32
        unsigned char c;
+#else
+       char c;
+#endif
        int n = 0;
        char *p;
        if (socket_wait(ftp->ctrl_fd, 1) <= 0) return 0;
@@ -260,6 +287,7 @@ int kftp_reconnect(knetFile *ftp)
                ftp->ctrl_fd = -1;
        }
        netclose(ftp->fd);
+       ftp->fd = -1;
        return kftp_connect(ftp);
 }
 
@@ -300,18 +328,26 @@ int kftp_connect_file(knetFile *fp)
        }
        kftp_pasv_prep(fp);
     kftp_send_cmd(fp, fp->size_cmd, 1);
+#ifndef _WIN32
     if ( sscanf(fp->response,"%*d %lld", &file_size) != 1 )
     {
         fprintf(stderr,"[kftp_connect_file] %s\n", fp->response);
         return -1;
-    } else fp->file_size = file_size;
+    }
+#else
+       const char *p = fp->response;
+       while (*p != ' ') ++p;
+       while (*p < '0' || *p > '9') ++p;
+       file_size = strtoint64(p);
+#endif
+       fp->file_size = file_size;
        if (fp->offset>=0) {
                char tmp[32];
 #ifndef _WIN32
                sprintf(tmp, "REST %lld\r\n", (long long)fp->offset);
 #else
                strcpy(tmp, "REST ");
-               uint64tostr(tmp + 5, fp->offset);
+               int64tostr(tmp + 5, fp->offset);
                strcat(tmp, "\r\n");
 #endif
                kftp_send_cmd(fp, tmp, 1);
@@ -492,7 +528,7 @@ off_t knet_read(knetFile *fp, void *buf, off_t len)
        return l;
 }
 
-off_t knet_seek(knetFile *fp, off_t off, int whence)
+off_t knet_seek(knetFile *fp, int64_t off, int whence)
 {
        if (whence == SEEK_SET && off == fp->offset) return 0;
        if (fp->type == KNF_TYPE_LOCAL) {
index f5fa0fcfd6fdb9a25e02ee777d68c8a2301d23b0..0a0e66f7a0aaeb65eac7068b687a5af945419e70 100644 (file)
@@ -9,7 +9,7 @@
 #define netwrite(fd, ptr, len) write(fd, ptr, len)
 #define netclose(fd) close(fd)
 #else
-#include <winsock.h>
+#include <winsock2.h>
 #define netread(fd, ptr, len) recv(fd, ptr, len, 0)
 #define netwrite(fd, ptr, len) send(fd, ptr, len, 0)
 #define netclose(fd) closesocket(fd)
@@ -65,7 +65,7 @@ extern "C" {
          This routine only sets ->offset and ->is_ready=0. It does not
          communicate with the FTP server.
         */
-       off_t knet_seek(knetFile *fp, off_t off, int whence);
+       off_t knet_seek(knetFile *fp, int64_t off, int whence);
        int knet_close(knetFile *fp);
 
 #ifdef __cplusplus