From fa2d611c7e7767ab53c8cf56130dd8555313113b Mon Sep 17 00:00:00 2001 From: superturbocat2001 Date: Mon, 18 Jan 2021 22:04:07 +0000 Subject: [PATCH] Fixed strerror function and added socket error handling. Cleared all libck warnings. Updated libimg.h git-svn-id: svn://kolibrios.org@8540 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/develop/ktcc/trunk/bin/lib/libck.a | Bin 135698 -> 136922 bytes programs/develop/ktcc/trunk/libc/fs/dir.c | 10 +- .../ktcc/trunk/libc/include/clayer/libimg.h | 38 +++--- .../ktcc/trunk/libc/include/kolibrisys.h | 4 +- programs/develop/ktcc/trunk/libc/net/socket.c | 2 + .../develop/ktcc/trunk/libc/stdio/debug.c | 1 + .../develop/ktcc/trunk/libc/string/strerror.c | 108 +++++++++++++----- .../develop/ktcc/trunk/samples/build_all.sh | 1 + .../ktcc/trunk/samples/net/tcpsrv_demo.c | 12 +- 9 files changed, 121 insertions(+), 55 deletions(-) diff --git a/programs/develop/ktcc/trunk/bin/lib/libck.a b/programs/develop/ktcc/trunk/bin/lib/libck.a index 81cdd3484fbef225bab41d256915a10028700fb5..8ce03410102fcd497ea33c50c8e97e2806cdf6eb 100644 GIT binary patch delta 2613 zcmb_dYitx%6h3F#ZAxhhEiHDpTbSAgK@gEbfeJyOY$T~x9@Q8WoZY#*Y}lPy=TRt- zjFAu@QHX5KM1lmBU_(SPJ|IRS3Nc1dkVs-c6fl?&2tf$iDv0NHW;@$K5>5E=%{SjY z-?`_UJF~MJw-q1XS-eXStok0nQ4;`1Zw4G22E3;ma6&QQ#HRo!T>zY705(4eID_Id zKXfo>4Pb=yywQNIg&r2{0c`&i@bRG@7XJvCL-Zv;j>M^cSp7oD0A_XpYL@`bBY-RS z-Hg?T0B;A@e-HQy)$4l40<>w$P1NPY2Vftp z+|4a`FEy8seMNwuuW_(H3dnKbvV$+b0Oa`UQ3qc?0LXEWPL$)DEe;OH0duhU&3CID z9Q_+GAIHLgw*$vZ069*4JP@ZMU?E-b^u>Yr_bFT3Vp`;p0UUmYVtyZ?AjnDm-rmuIR^VeXX!z>&!*H?cyfi$@t)_X^o6>- z&Mg|2k*;#}Tg015 z*SWfzcrR(UVBfy91Pka}TLJdbFv{7*qw2HmSB3;z$4_hmx=i7hsr)jHE{zkwo?MHo zt&eC9q`{7GrmypP&eUfSZI6{yk~8%&oiiQSW1ML&jdL}?%baPBZq9Vz`#IMD{KPp7 z(95|NppsfcI?#JLkEH!Li(tnX+0B6YS znTx?MrX_s!5S-TzmVBA8a4^{A>ocHIn)O!f?L~MOSpGL?=7CF7K)d68%Uxhk_$d`! zE7x0pCkDplF6(5Mo8;o%ZQla!m;mmY`C;|)4g6R8FMwSR)`Oj5U4sw&9+u5@cXT>< z?11CMW>7hq?>O}wR8FsRoc#t=&dE2boWJa7+zNJyslkPPj*FAP?wU%#p77_VpmO=a zyRNQ8jPk_mx$nB^1(lY@p3y4*(8^yo9Bp-=a<5o^|NFoHKM&V{%A?(m_Br6=X2;W7 z@L50bx!lx?R`69Z`1%qwEP}=(j$X~s+|!`--UcnjlMAhHJ+%H_XsK(U4QPcna5l8G z`qj1WhFUkzq`SsWp5U)r!BHYm%q;P17JaEd5NPWQV0FhoBH*Q0v}Q3){Oo1_!dC;o zOP7^H5`LWZvTai0-WN%wY>F`+dc-xAdzMtZEAwyG=twFxLc~nctVRfnazSs*wNBb!?t0VLEQ@Jp>TzPkYEnSPmG%7 zrnTJcoYU5qylzAy zRs@00HT9rjhK(SC#3iY_VBD~(DkQlpw0%FMylmZet)%o@Ea zVyVUr8&R=)7>CB2JZU?dhmrj<K9*qEQjqWIX)Mh+TRtQ`K4WUOR^<}@7G}n)_6%~lfK~COejiK3 O_5~c$(Bb3lNB;t}z`Nl9 diff --git a/programs/develop/ktcc/trunk/libc/fs/dir.c b/programs/develop/ktcc/trunk/libc/fs/dir.c index 708379096d..fcf5a877fc 100644 --- a/programs/develop/ktcc/trunk/libc/fs/dir.c +++ b/programs/develop/ktcc/trunk/libc/fs/dir.c @@ -1,3 +1,5 @@ +/* Copyright (C) 2019-2021 Logaev Maxim (turbocat2001), GPLv3 */ + #include #include #include @@ -43,9 +45,9 @@ int lsdir(const char* dir, short_file_info **list) inf.p00 = 1; inf.p04 = 0; inf.p12 = 2; - inf.p16 = (unsigned*) malloc(32+inf.p12*560); + inf.p16 = (unsigned) malloc(32+inf.p12*560); inf.p20 = 0; - inf.p21 = dir; + inf.p21 = (char*)dir; if(kol_file_70(&inf)) { @@ -97,10 +99,10 @@ void setcwd(const char* cwd) bool rmdir(const char* dir) { - return dir_operations(8, dir); + return dir_operations(8, (char*)dir); } bool mkdir(const char* dir) { - return dir_operations(9, dir); + return dir_operations(9, (char*)dir); } diff --git a/programs/develop/ktcc/trunk/libc/include/clayer/libimg.h b/programs/develop/ktcc/trunk/libc/include/clayer/libimg.h index 63ab149dec..fc11be9976 100644 --- a/programs/develop/ktcc/trunk/libc/include/clayer/libimg.h +++ b/programs/develop/ktcc/trunk/libc/include/clayer/libimg.h @@ -1,6 +1,7 @@ #ifndef KOLIBRI_LIBIMG_H #define KOLIBRI_LIBIMG_H +#include extern int kolibri_libimg_init(void); //list of format id's @@ -19,6 +20,17 @@ extern int kolibri_libimg_init(void); #define LIBIMG_FORMAT_XBM 13 #define LIBIMG_FORMAT_Z80 14 +#define IMAGE_BPP8i 1 // indexed +#define IMAGE_BPP24 2 +#define IMAGE_BPP32 3 +#define IMAGE_BPP15 4 +#define IMAGE_BPP16 5 +#define IMAGE_BPP1 6 +#define IMAGE_BPP8g 7 // grayscale +#define IMAGE_BPP2i 8 +#define IMAGE_BPP4i 9 +#define IMAGE_BPP8a 10 + //error codes #define LIBIMG_ERROR_OUT_OF_MEMORY 1 #define LIBIMG_ERROR_FORMAT 2 @@ -47,18 +59,18 @@ extern int kolibri_libimg_init(void); #define ROTATE_90_CCW ROTATE_270_CW #define ROTATE_270_CCW ROTATE_90_CW -extern void* (*img_decode __attribute__((__stdcall__)))(void *, uint32_t, uint32_t); -extern void* (*img_encode __attribute__((__stdcall__)))(void *, uint32_t, uint32_t); -extern void* (*img_create __attribute__((__stdcall__)))(uint32_t, uint32_t, uint32_t); -extern void (*img_to_rgb2 __attribute__((__stdcall__)))(void *, void *); -extern void* (*img_to_rgb __attribute__((__stdcall__)))(void *); -extern uint32_t (*img_flip __attribute__((__stdcall__)))(void *, uint32_t); -extern uint32_t (*img_flip_layer __attribute__((__stdcall__)))(void *, uint32_t); -extern uint32_t (*img_rotate __attribute__((__stdcall__)))(void *, uint32_t); -extern uint32_t (*img_rotate_layer __attribute__((__stdcall__)))(void *, uint32_t); -extern void (*img_draw __attribute__((__stdcall__)))(void *, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t ); -extern uint32_t (*img_count __attribute__((__stdcall__)))(void *); -extern uint32_t (*img_destroy __attribute__((__stdcall__)))(void *) ; -extern uint32_t (*img_destroy_layer __attribute__((__stdcall__)))(void *); +extern void* (*img_decode __attribute__((__stdcall__)))(void* file_data, uint32_t length, uint32_t options); +extern void* (*img_encode __attribute__((__stdcall__)))(void* image_data, uint32_t length, uint32_t option); +extern void* (*img_create __attribute__((__stdcall__)))(uint32_t width, uint32_t height, uint32_t type); +extern void (*img_to_rgb2 __attribute__((__stdcall__)))(void* image_data, void *rgb_data); +extern void* (*img_to_rgb __attribute__((__stdcall__)))(void *image_data); +extern uint32_t (*img_flip __attribute__((__stdcall__)))(void* image_data, uint32_t flip); +extern uint32_t (*img_flip_layer __attribute__((__stdcall__)))(void *image_data, uint32_t flip); +extern uint32_t (*img_rotate __attribute__((__stdcall__)))(void* image_data, uint32_t rotate); +extern uint32_t (*img_rotate_layer __attribute__((__stdcall__)))(void* image_data, uint32_t rotate); +extern void (*img_draw __attribute__((__stdcall__)))(void *image_data, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t xoff, uint32_t yoff); +extern uint32_t (*img_count __attribute__((__stdcall__)))(void *image_data); +extern uint32_t (*img_destroy __attribute__((__stdcall__)))(void *image_data); +extern uint32_t (*img_destroy_layer __attribute__((__stdcall__)))(void* image_data); #endif /* KOLIBRI_LIBIMG_H */ diff --git a/programs/develop/ktcc/trunk/libc/include/kolibrisys.h b/programs/develop/ktcc/trunk/libc/include/kolibrisys.h index cebe22b502..b4a4fd79f8 100644 --- a/programs/develop/ktcc/trunk/libc/include/kolibrisys.h +++ b/programs/develop/ktcc/trunk/libc/include/kolibrisys.h @@ -15,7 +15,7 @@ #define cdecl __attribute__ ((cdecl)) #define stdcall __attribute__ ((stdcall)) //#endif - +typedef void* func_ptr; typedef unsigned int dword; typedef unsigned char byte; typedef unsigned short word; @@ -191,7 +191,7 @@ extern void stdcall _ksys_sound_speaker_play(void* data); //------------------function for work with Dinamic Link Librarys(DLL)-------------- extern dword* stdcall _ksys_cofflib_load(char* name); -extern char* stdcall _ksys_cofflib_getproc(void* exp,char* sz_name); +extern func_ptr stdcall _ksys_cofflib_getproc(void* exp,char* sz_name); //--------------------------------------------------------------------------------- #endif diff --git a/programs/develop/ktcc/trunk/libc/net/socket.c b/programs/develop/ktcc/trunk/libc/net/socket.c index b05b8d8c91..15c2159fb5 100644 --- a/programs/develop/ktcc/trunk/libc/net/socket.c +++ b/programs/develop/ktcc/trunk/libc/net/socket.c @@ -1,3 +1,5 @@ +/* Copyright (C) 2019-2021 Logaev Maxim (turbocat2001), GPLv3 */ + #include int socket(int domain, int type, int protocol) diff --git a/programs/develop/ktcc/trunk/libc/stdio/debug.c b/programs/develop/ktcc/trunk/libc/stdio/debug.c index ab8209e1b3..be8d62514d 100644 --- a/programs/develop/ktcc/trunk/libc/stdio/debug.c +++ b/programs/develop/ktcc/trunk/libc/stdio/debug.c @@ -1,4 +1,5 @@ #include +#include #include void debug_printf(const char *format,...) diff --git a/programs/develop/ktcc/trunk/libc/string/strerror.c b/programs/develop/ktcc/trunk/libc/string/strerror.c index 50e1e829c5..58b8988fe3 100644 --- a/programs/develop/ktcc/trunk/libc/string/strerror.c +++ b/programs/develop/ktcc/trunk/libc/string/strerror.c @@ -1,59 +1,105 @@ #include +#include char* strerror(int err) { char *msg; switch(err) { - case 0: - msg = "success"; + case E_SUCCESS: + msg = "Success"; break; case -1: - msg = "end of file"; + msg = "End of file"; break; - case -2: - msg = "function is not supported for the given file system"; + case E_UNSUPPORTED: + msg = "Function is not supported for the given file system"; break; - case -3: - msg = "unknown file system"; + case E_UNKNOWNFS: + msg = "Unknown file system"; break; - case -5: - msg = "file not found"; + case E_NOTFOUND: + msg = "File not found"; break; - case -6: - msg = "end of file, EOF"; + case E_EOF: + msg = "End of file, EOF"; break; - case -7: - msg = "pointer lies outside of application memory"; + case E_INVALIDPTR: + msg = "Pointer lies outside of application memory"; break; - case -8: - msg = "disk is full"; + case E_DISKFULL: + msg = "Disk is full"; break; - case -9: - msg = "file system error"; + case E_FSYSERROR: + msg = "Dile system error"; break; - case -10: - msg = "access denied"; + case E_ACCESS: + msg = "Access denied"; break; - case -11: - msg = "device error"; + case E_HARDWARE: + msg = "Device error"; break; - case -12: - msg = "file system requires more memory"; + case E_NOMEM: + msg = "File system requires more memory"; break; - case -30: - msg = "not enough memory"; + case E_NOMEM2: + msg = "Not enough memory"; break; - case -31: - msg = "file is not executable"; + case E_FILEFMT: + msg = "File is not executable"; break; - case -32: - msg = "too many processes"; + case E_TOOMANY: + msg = "Too many processes"; + break; + /* Socket errors */ + case ENOBUFS: + msg = "Broken buffer"; + break; + case EINPROGRESS: + msg = "Operation now in progress"; + break; + case EOPNOTSUPP: + msg = "Operation not supported on transport endpoint"; + break; + case EWOULDBLOCK: + msg = "Operation would block"; + break; + case ENOTCONN: + msg = "Transport endpoint is not connected"; + break; + case EALREADY: + msg = "Operation already in progress"; + break; + case EINVALUE: + msg = "Invalid argument"; + break; + case EMSGSIZE: + msg = "Message too long"; + break; + case ENOMEM: + msg = "Out of memory"; + break; + case EADDRINUSE: + msg = "Address already in use"; + break; + case ECONNREFUSED: + msg = "Connection refused"; + break; + case ECONNRESET: + msg = "Connection reset by peer"; + break; + case EISCONN: + msg = "Transport endpoint is already connected"; + break; + case ETIMEDOUT: + msg = "Connection timed out"; + break; + case ECONNABORTED: + msg = "Software caused connection abort"; break; default: - msg = "unknown error"; + msg = "Unknown error"; break; } - return msg; } diff --git a/programs/develop/ktcc/trunk/samples/build_all.sh b/programs/develop/ktcc/trunk/samples/build_all.sh index b1fdd5d298..8f46b93563 100644 --- a/programs/develop/ktcc/trunk/samples/build_all.sh +++ b/programs/develop/ktcc/trunk/samples/build_all.sh @@ -10,6 +10,7 @@ ../tcc clayer/rasterworks.c -lck -lrasterworks -o /tmp0/1/rasterworks ../tcc clayer/boxlib.c -lck -lbox -o /tmp0/1/boxlib_ex ../tcc clayer/libimg.c -lck -limg -o /tmp0/1/libimg_ex +cp clayer/kolibrios.jpg /tmp0/1/kolibrios.jpg ../tcc clayer/dialog.c -lck -ldialog -o /tmp0/1/dialog_ex ../tcc dir_example.c -lck -o /tmp0/1/dir_example ../tcc net/tcpsrv_demo.c -lck -o /tmp0/1/tcpsrv_demo diff --git a/programs/develop/ktcc/trunk/samples/net/tcpsrv_demo.c b/programs/develop/ktcc/trunk/samples/net/tcpsrv_demo.c index 405198ddae..5e8b64cf01 100644 --- a/programs/develop/ktcc/trunk/samples/net/tcpsrv_demo.c +++ b/programs/develop/ktcc/trunk/samples/net/tcpsrv_demo.c @@ -11,18 +11,20 @@ int main() struct sockaddr addr={AF_INET4, PORT(23) , 0, 0}; int sk1=socket(AF_INET4, SOCK_STREAM, IPPROTO_TCP); - printf("Open socket: %d. Error: %d\n",sk1, errno); + printf("Open socket: %d. Status: %s\n",sk1, strerror(errno)); bind(sk1, &addr,sizeof(addr)); - printf("Socket binding. Error: %d\n", errno); + printf("Socket binding. Status: %s\n", strerror(errno)); listen(sk1, 1); - printf("Listening to a socket. Error: %d\n", errno); + printf("Listening to a socket. Status: %s\n", strerror(errno)); + printf("You can connect to 'tcp server' via 'telnet' on localhost:23 !"); + int sk2 = accept(sk1, &addr, sizeof(addr)); - printf("Accept done. Error: %d\n", errno); + printf("Accept done. Status: %s\n", strerror(errno)); send(sk2, msg1, strlen(msg1),MSG_NOFLAG); - printf("Send message: '%s' Error: %d\n", msg1, errno); + printf("Send message: '%s'. Status: %s\n",msg1, strerror(errno)); puts("Received data:"); while(msg2!='!') {