選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

117 行
3.0 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; you can redistribute it and/or
  10. * modify it under the terms of the Do What The Fuck You Want To
  11. * Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * This file contains replacement functions for the standard C library
  16. * that must be used when building libcucul and libcaca into a kernel.
  17. */
  18. /* Various defines */
  19. #define NULL ((void *)0)
  20. #define BUFSIZ 4096
  21. #define RAND_MAX ((unsigned int)0x8000000)
  22. #define INT_MAX ((int)0x7fffffff)
  23. #define M_PI 3.14159265358979323846
  24. #define __BYTE_ORDER 1
  25. #define __BIG_ENDIAN 2
  26. /* Assembly code for outb and inb */
  27. extern inline void outb(unsigned char val, unsigned short port);
  28. extern inline unsigned char inb(unsigned short port);
  29. extern inline void outb(unsigned char val, unsigned short port)
  30. {
  31. __asm__ __volatile__ ("outb %b0,%w1" : : "a" (val), "Nd" (port));
  32. }
  33. extern inline unsigned char inb(unsigned short port)
  34. {
  35. unsigned char tmp;
  36. __asm__ __volatile__ ("inb %w1,%0" : "=a" (tmp) : "Nd" (port));
  37. return tmp;
  38. }
  39. /* Various typedefs -- some are x86-specific */
  40. #define CUSTOM_INTTYPES
  41. typedef unsigned char uint8_t;
  42. typedef unsigned short uint16_t;
  43. typedef unsigned long int uint32_t;
  44. typedef long int intptr_t;
  45. typedef long unsigned int uintptr_t;
  46. typedef unsigned int size_t;
  47. typedef struct file
  48. {
  49. void *mem;
  50. } FILE;
  51. struct timeval {
  52. int tv_sec;
  53. int tv_usec;
  54. };
  55. struct timezone {
  56. int tz_minuteswest;
  57. int tz_dsttime;
  58. };
  59. /* Multiboot kernel entry point */
  60. void cmain(unsigned long int magic, unsigned long int addr);
  61. /* The application's entry point */
  62. int main(int argc, char *argv[]);
  63. /* stdlib.h functions */
  64. void *malloc(size_t size);
  65. void free(void *ptr);
  66. void *realloc(void *ptr, size_t size);
  67. char *getenv(const char *name);
  68. int rand(void);
  69. int abs(int j);
  70. void exit(int status);
  71. /* string.h functions */
  72. void *memset(void *s, int c, size_t n);
  73. void *memcpy(void *dest, const void *src, size_t n);
  74. size_t strlen(const char *s);
  75. int strcasecmp(const char *s1, const char *s2);
  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. /* stdio.h functions */
  82. FILE *fopen(const char *path, const char *mode);
  83. int feof(FILE *stream);
  84. char *fgets(char *s, int size, FILE *stream);
  85. int fclose(FILE *fp);
  86. int printf(const char *format, ...);
  87. int sprintf(char *str, const char *format, ...);
  88. int sscanf(const char *str, const char *format, ...);
  89. /* unistd.h functions */
  90. void usleep(unsigned long usec);
  91. /* time.h functions */
  92. int gettimeofday(struct timeval *tv, struct timezone *tz);
  93. /* math.h functions */
  94. double cos(double x);
  95. double sin(double x);
  96. double sqrt(double x);