]> Nishi Git Mirror - libw3.git/commitdiff
error handling
authornishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Thu, 18 Jan 2024 11:31:39 +0000 (11:31 +0000)
committernishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Thu, 18 Jan 2024 11:31:39 +0000 (11:31 +0000)
git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@30 d27a3e52-49c5-7645-884c-6793ebffc270

Example/fetch.c
Library/Core.c
Library/DNS.c
Makefile

index 5a991744ddf1e48c2a5c668a2459f2bc7863d043..060e9768a263c43ec542a1618b1b3af6a0e76020 100644 (file)
@@ -21,8 +21,14 @@ int main(int argc, char** argv){
        }
        W3_Library_Init();
        struct W3* w3 = W3_Create("http", argv[1], 80);
-       W3_Set_Method(w3, "GET");
-       W3_Set_Path(w3, argv[2]);
-       W3_Send_Request(w3);
-       W3_Free(w3);
+       if(w3 != NULL){
+               W3_Set_Method(w3, "GET");
+               W3_Set_Path(w3, argv[2]);
+               W3_Send_Request(w3);
+               W3_Free(w3);
+       }else{
+               fprintf(stderr, "Failed to fetch\n");
+               return 1;
+       }
+       return 0;
 }
index 4ce4b2180d624984c69abb01a669b6ba3bf11e9a..b04c10ae3ad572865888ace21a735e7f7e3e0baf 100644 (file)
@@ -63,6 +63,10 @@ struct W3* W3_Create(const char* protocol, const char* hostname, int port){
        &w3->ssl_ctx
 #endif
        );
+       if(w3->sock == -1){
+               W3_Free(w3);
+               w3 = NULL;
+       }
        return w3;
 }
 
index a612569eebf72244d1030beb21473b3c7c9ffda5..a3b61796d5df9d81d3d36df87c1f78595be3fbc9 100644 (file)
@@ -51,6 +51,7 @@ int __W3_DNS_Connect(const char* hostname, bool ssl, uint16_t port
        sprintf(strport, "%d", port);
        s = getaddrinfo(hostname, strport, &hints, &result);
        if(s != 0){
+               free(strport);
                __W3_Debug("Resolve", "Failed");
                return -1;      /* Failed to resolve */
        }
index bb03e3e58b1048cbdf54693edf9d17d4b21ac2e7..ede14fa305b0bf9fdcbfa58c66271747892d89b3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -46,7 +46,7 @@ all: ./w3.pc ./Library/W3Version.h $(ALL)
        $(MAKE) -C ./Example CC=$(CC) fetch
 
 ./Library/W3Version.h:
-       m4 -DSUFFIX=\"/W\" ./W3Version.h.p > $@
+       m4 -DSUFFIX=\"W\" ./W3Version.h.p > $@
 
 else
 
@@ -106,4 +106,5 @@ endif
        -cp LICENSE w3-$(VERSION)/
        tar czvf w3-$(VERSION).tar.gz w3-$(VERSION)
        zip -rv w3-$(VERSION).zip w3-$(VERSION)
+       -/usr/lha/bin/lha a w3-$(VERSION).lzh w3-$(VERSION)
        rm -rf w3-$(VERSION)