Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

137 rader
3.8 KiB

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