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 <dir.h>
#include <stdbool.h>
@ -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);
}

View File

@ -1,6 +1,7 @@
#ifndef KOLIBRI_LIBIMG_H
#define KOLIBRI_LIBIMG_H
#include <stddef.h>
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 */

View File

@ -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

View File

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

View File

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

View File

@ -1,59 +1,105 @@
#include <string.h>
#include <errno.h>
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;
}

View File

@ -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

View File

@ -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!='!')
{