You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

klibc.h 4.3 KiB

15 vuotta sitten
15 vuotta sitten
15 vuotta sitten
15 vuotta sitten
15 vuotta sitten
15 vuotta sitten
15 vuotta sitten
15 vuotta sitten
15 vuotta sitten
15 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * libcaca
  3. * libcaca Colour ASCII-Art library
  4. * Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
  5. * 2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
  6. * All Rights Reserved
  7. *
  8. * $Id: kernel.h 4154 2009-12-20 13:33:11Z jylam $
  9. *
  10. * This library is free software. It comes without any warranty, to
  11. * the extent permitted by applicable law. You can redistribute it
  12. * and/or modify it under the terms of the Do What The Fuck You Want
  13. * To Public License, Version 2, as published by Sam Hocevar. See
  14. * http://sam.zoy.org/wtfpl/COPYING for more details.
  15. */
  16. /*
  17. * This file contains replacement functions for the standard C library
  18. * that must be used when building libcaca and libcaca into a kernel.
  19. */
  20. /* Various typedefs -- some are x86-specific */
  21. #define CUSTOM_INTTYPES
  22. #define outb(port,value) __asm__ __volatile__ ("outb %%al,%%dx"::"d" (port), "a" (value));
  23. #define outbp(port,value) __asm __volatile__ ("outb %%al,%%dx; jmp 1f; 1:"::"d" (port), "a" (value));
  24. #define inb(port) ({unsigned char _v; __asm__ __volatile__ ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); _v; })
  25. /* Various defines */
  26. #define NULL ((void *)0)
  27. #define EOF (-1)
  28. #define BUFSIZ 4096
  29. #define RAND_MAX ((unsigned int)0x8000000)
  30. #define INT_MAX ((int)0x7fffffff)
  31. #define M_PI 3.14159265358979323846
  32. #define __BYTE_ORDER 1
  33. #define __BIG_ENDIAN 2
  34. typedef unsigned char u8;
  35. typedef unsigned short u16;
  36. typedef unsigned int u32;
  37. typedef unsigned long int u64;
  38. #ifndef size_t
  39. typedef unsigned int size_t;
  40. #endif
  41. typedef struct file
  42. {
  43. void *mem;
  44. } FILE;
  45. struct timeval
  46. {
  47. int tv_sec;
  48. int tv_usec;
  49. };
  50. struct timezone
  51. {
  52. int tz_minuteswest;
  53. int tz_dsttime;
  54. };
  55. /* stdlib.h functions */
  56. void *malloc(size_t size);
  57. void free(void *ptr);
  58. void *realloc(void *ptr, size_t size);
  59. char *getenv(const char *name);
  60. int rand(void);
  61. int abs(int j);
  62. void exit(int status);
  63. void srand(unsigned int s);
  64. int atexit(void (*function) (void));
  65. FILE *stdin, *stdout, *stderr;
  66. /* string.h functions */
  67. void *memset(void *s, int c, size_t n);
  68. void *memcpy(void *dest, const void *src, size_t n);
  69. void *memmove(void *dest, const void *src, size_t n);
  70. size_t strlen(const char *s);
  71. int strcmp(const char *s1, const char *s2);
  72. int strcasecmp(const char *s1, const char *s2);
  73. int memcmp(const void *s1, const void *s2, size_t n);
  74. char *strdup(const char *s);
  75. char *strchr(const char *s, int c);
  76. /* stdarg.h functions */
  77. typedef void *va_list;
  78. #define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
  79. #define va_end(v)
  80. int vsnprintf(char *str, size_t size, const char *format, va_list ap);
  81. /* va_arg */
  82. #define args_list char *
  83. #define _arg_stack_size(type) (((sizeof(type)-1)/sizeof(int)+1)*sizeof(int))
  84. #define args_start(ap, fmt) do { \
  85. ap = (char *)((unsigned int)&fmt + _arg_stack_size(&fmt)); \
  86. } while (0)
  87. #define args_end(ap)
  88. #define args_next(ap, type) (((type *)(ap+=_arg_stack_size(type)))[-1])
  89. /* stdio.h functions */
  90. FILE *fopen(const char *path, const char *mode);
  91. int feof(FILE * stream);
  92. char *fgets(char *s, int size, FILE * stream);
  93. size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE * stream);
  94. int fclose(FILE * fp);
  95. int printf(const char *format, ...);
  96. int fprintf(FILE * stream, const char *format, ...);
  97. int fflush(FILE * stream);
  98. int sprintf(char *str, const char *format, ...);
  99. int sscanf(const char *str, const char *format, ...);
  100. void itoa(int n, char s[]);
  101. void clearscreen(void);
  102. /* unistd.h functions */
  103. void usleep(unsigned long usec);
  104. void sleep(unsigned long sec);
  105. int getpid(void);
  106. /* time.h functions */
  107. u64 rdtsc(void);
  108. int gettimeofday(struct timeval *tv, struct timezone *tz);
  109. int time(void *);
  110. /* math.h functions */
  111. double cos(double x);
  112. double sin(double x);
  113. double sqrt(double x);
  114. /* errno.h functions */
  115. #define ENOENT 2 /* No such file or directory */
  116. #define ENOMEM 12 /* Out of memory */
  117. #define EBUSY 16 /* Device or resource busy */
  118. #define ENODEV 19 /* No such device */
  119. #define EINVAL 22 /* Invalid argument */
  120. #define ENOTTY 25 /* Not a typewriter */
  121. #define ENOSYS 38 /* Function not implemented */
  122. extern int errno;
  123. /* arpa/inet.h functions */
  124. unsigned int htonl(unsigned int hostlong);
  125. unsigned short htons(unsigned short hostlong);
  126. void print(char *str);