Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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