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
This commit is contained in:
superturbocat2001 2021-01-18 22:04:07 +00:00
parent 23d2e1da69
commit fa2d611c7e
9 changed files with 121 additions and 55 deletions

View File

@ -1,3 +1,5 @@
/* Copyright (C) 2019-2021 Logaev Maxim (turbocat2001), GPLv3 */
#include <stdlib.h> #include <stdlib.h>
#include <dir.h> #include <dir.h>
#include <stdbool.h> #include <stdbool.h>
@ -43,9 +45,9 @@ int lsdir(const char* dir, short_file_info **list)
inf.p00 = 1; inf.p00 = 1;
inf.p04 = 0; inf.p04 = 0;
inf.p12 = 2; inf.p12 = 2;
inf.p16 = (unsigned*) malloc(32+inf.p12*560); inf.p16 = (unsigned) malloc(32+inf.p12*560);
inf.p20 = 0; inf.p20 = 0;
inf.p21 = dir; inf.p21 = (char*)dir;
if(kol_file_70(&inf)) if(kol_file_70(&inf))
{ {
@ -97,10 +99,10 @@ void setcwd(const char* cwd)
bool rmdir(const char* dir) bool rmdir(const char* dir)
{ {
return dir_operations(8, dir); return dir_operations(8, (char*)dir);
} }
bool mkdir(const char* dir) bool mkdir(const char* dir)
{ {
return dir_operations(9, dir); return dir_operations(9, (char*)dir);
} }

View File

@ -1,6 +1,7 @@
#ifndef KOLIBRI_LIBIMG_H #ifndef KOLIBRI_LIBIMG_H
#define KOLIBRI_LIBIMG_H #define KOLIBRI_LIBIMG_H
#include <stddef.h>
extern int kolibri_libimg_init(void); extern int kolibri_libimg_init(void);
//list of format id's //list of format id's
@ -19,6 +20,17 @@ extern int kolibri_libimg_init(void);
#define LIBIMG_FORMAT_XBM 13 #define LIBIMG_FORMAT_XBM 13
#define LIBIMG_FORMAT_Z80 14 #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 //error codes
#define LIBIMG_ERROR_OUT_OF_MEMORY 1 #define LIBIMG_ERROR_OUT_OF_MEMORY 1
#define LIBIMG_ERROR_FORMAT 2 #define LIBIMG_ERROR_FORMAT 2
@ -47,18 +59,18 @@ extern int kolibri_libimg_init(void);
#define ROTATE_90_CCW ROTATE_270_CW #define ROTATE_90_CCW ROTATE_270_CW
#define ROTATE_270_CCW ROTATE_90_CW #define ROTATE_270_CCW ROTATE_90_CW
extern void* (*img_decode __attribute__((__stdcall__)))(void *, uint32_t, uint32_t); extern void* (*img_decode __attribute__((__stdcall__)))(void* file_data, uint32_t length, uint32_t options);
extern void* (*img_encode __attribute__((__stdcall__)))(void *, uint32_t, uint32_t); extern void* (*img_encode __attribute__((__stdcall__)))(void* image_data, uint32_t length, uint32_t option);
extern void* (*img_create __attribute__((__stdcall__)))(uint32_t, uint32_t, uint32_t); extern void* (*img_create __attribute__((__stdcall__)))(uint32_t width, uint32_t height, uint32_t type);
extern void (*img_to_rgb2 __attribute__((__stdcall__)))(void *, void *); extern void (*img_to_rgb2 __attribute__((__stdcall__)))(void* image_data, void *rgb_data);
extern void* (*img_to_rgb __attribute__((__stdcall__)))(void *); extern void* (*img_to_rgb __attribute__((__stdcall__)))(void *image_data);
extern uint32_t (*img_flip __attribute__((__stdcall__)))(void *, uint32_t); extern uint32_t (*img_flip __attribute__((__stdcall__)))(void* image_data, uint32_t flip);
extern uint32_t (*img_flip_layer __attribute__((__stdcall__)))(void *, uint32_t); extern uint32_t (*img_flip_layer __attribute__((__stdcall__)))(void *image_data, uint32_t flip);
extern uint32_t (*img_rotate __attribute__((__stdcall__)))(void *, uint32_t); extern uint32_t (*img_rotate __attribute__((__stdcall__)))(void* image_data, uint32_t rotate);
extern uint32_t (*img_rotate_layer __attribute__((__stdcall__)))(void *, uint32_t); extern uint32_t (*img_rotate_layer __attribute__((__stdcall__)))(void* image_data, uint32_t rotate);
extern void (*img_draw __attribute__((__stdcall__)))(void *, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t ); 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 *); extern uint32_t (*img_count __attribute__((__stdcall__)))(void *image_data);
extern uint32_t (*img_destroy __attribute__((__stdcall__)))(void *) ; extern uint32_t (*img_destroy __attribute__((__stdcall__)))(void *image_data);
extern uint32_t (*img_destroy_layer __attribute__((__stdcall__)))(void *); extern uint32_t (*img_destroy_layer __attribute__((__stdcall__)))(void* image_data);
#endif /* KOLIBRI_LIBIMG_H */ #endif /* KOLIBRI_LIBIMG_H */

View File

@ -15,7 +15,7 @@
#define cdecl __attribute__ ((cdecl)) #define cdecl __attribute__ ((cdecl))
#define stdcall __attribute__ ((stdcall)) #define stdcall __attribute__ ((stdcall))
//#endif //#endif
typedef void* func_ptr;
typedef unsigned int dword; typedef unsigned int dword;
typedef unsigned char byte; typedef unsigned char byte;
typedef unsigned short word; 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)-------------- //------------------function for work with Dinamic Link Librarys(DLL)--------------
extern dword* stdcall _ksys_cofflib_load(char* name); 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 #endif

View File

@ -1,3 +1,5 @@
/* Copyright (C) 2019-2021 Logaev Maxim (turbocat2001), GPLv3 */
#include <net/socket.h> #include <net/socket.h>
int socket(int domain, int type, int protocol) int socket(int domain, int type, int protocol)

View File

@ -1,4 +1,5 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h>
#include <kolibrisys.h> #include <kolibrisys.h>
void debug_printf(const char *format,...) void debug_printf(const char *format,...)

View File

@ -1,59 +1,105 @@
#include <string.h> #include <string.h>
#include <errno.h>
char* strerror(int err) char* strerror(int err)
{ {
char *msg; char *msg;
switch(err) switch(err)
{ {
case 0: case E_SUCCESS:
msg = "success"; msg = "Success";
break; break;
case -1: case -1:
msg = "end of file"; msg = "End of file";
break; break;
case -2: case E_UNSUPPORTED:
msg = "function is not supported for the given file system"; msg = "Function is not supported for the given file system";
break; break;
case -3: case E_UNKNOWNFS:
msg = "unknown file system"; msg = "Unknown file system";
break; break;
case -5: case E_NOTFOUND:
msg = "file not found"; msg = "File not found";
break; break;
case -6: case E_EOF:
msg = "end of file, EOF"; msg = "End of file, EOF";
break; break;
case -7: case E_INVALIDPTR:
msg = "pointer lies outside of application memory"; msg = "Pointer lies outside of application memory";
break; break;
case -8: case E_DISKFULL:
msg = "disk is full"; msg = "Disk is full";
break; break;
case -9: case E_FSYSERROR:
msg = "file system error"; msg = "Dile system error";
break; break;
case -10: case E_ACCESS:
msg = "access denied"; msg = "Access denied";
break; break;
case -11: case E_HARDWARE:
msg = "device error"; msg = "Device error";
break; break;
case -12: case E_NOMEM:
msg = "file system requires more memory"; msg = "File system requires more memory";
break; break;
case -30: case E_NOMEM2:
msg = "not enough memory"; msg = "Not enough memory";
break; break;
case -31: case E_FILEFMT:
msg = "file is not executable"; msg = "File is not executable";
break; break;
case -32: case E_TOOMANY:
msg = "too many processes"; 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; break;
default: default:
msg = "unknown error"; msg = "Unknown error";
break; break;
} }
return msg; return msg;
} }

View File

@ -10,6 +10,7 @@
../tcc clayer/rasterworks.c -lck -lrasterworks -o /tmp0/1/rasterworks ../tcc clayer/rasterworks.c -lck -lrasterworks -o /tmp0/1/rasterworks
../tcc clayer/boxlib.c -lck -lbox -o /tmp0/1/boxlib_ex ../tcc clayer/boxlib.c -lck -lbox -o /tmp0/1/boxlib_ex
../tcc clayer/libimg.c -lck -limg -o /tmp0/1/libimg_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 clayer/dialog.c -lck -ldialog -o /tmp0/1/dialog_ex
../tcc dir_example.c -lck -o /tmp0/1/dir_example ../tcc dir_example.c -lck -o /tmp0/1/dir_example
../tcc net/tcpsrv_demo.c -lck -o /tmp0/1/tcpsrv_demo ../tcc net/tcpsrv_demo.c -lck -o /tmp0/1/tcpsrv_demo

View File

@ -11,18 +11,20 @@ int main()
struct sockaddr addr={AF_INET4, PORT(23) , 0, 0}; struct sockaddr addr={AF_INET4, PORT(23) , 0, 0};
int sk1=socket(AF_INET4, SOCK_STREAM, IPPROTO_TCP); 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)); bind(sk1, &addr,sizeof(addr));
printf("Socket binding. Error: %d\n", errno); printf("Socket binding. Status: %s\n", strerror(errno));
listen(sk1, 1); 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)); 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); 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:"); puts("Received data:");
while(msg2!='!') while(msg2!='!')
{ {