cgeneric.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by the Free Pascal development team.
  4. Processor independent implementation for the system unit
  5. (based on libc)
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {****************************************************************************
  13. Primitives
  14. ****************************************************************************}
  15. {$ifndef FPC_SYSTEM_HAS_MOVE}
  16. {$define FPC_SYSTEM_HAS_MOVE}
  17. procedure bcopy(const source;var dest;count:sizeuint); cdecl; external 'c' name 'bcopy';
  18. { we need this separate move declaration because we can't add a "public, alias" to the above }
  19. procedure Move(const source;var dest;count:sizeint); [public, alias: 'FPC_MOVE'];{$ifdef SYSTEMINLINE}inline;{$endif}
  20. begin
  21. if count <= 0 then
  22. exit;
  23. bcopy(source,dest,count);
  24. end;
  25. {$endif not FPC_SYSTEM_HAS_MOVE}
  26. {$ifndef FPC_SYSTEM_HAS_FILLCHAR}
  27. {$define FPC_SYSTEM_HAS_FILLCHAR}
  28. procedure memset(var x; value: byte; count: sizeuint); cdecl; external 'c';
  29. Procedure FillChar(var x;count: sizeint;value:byte);{$ifdef SYSTEMINLINE}inline;{$endif}
  30. begin
  31. if count <= 0 then
  32. exit;
  33. memset(x,value,count);
  34. end;
  35. {$endif FPC_SYSTEM_HAS_FILLCHAR}
  36. {$ifndef FPC_SYSTEM_HAS_FILLBYTE}
  37. {$define FPC_SYSTEM_HAS_FILLBYTE}
  38. procedure FillByte (var x;count : sizeint;value : byte );{$ifdef SYSTEMINLINE}inline;{$endif}
  39. begin
  40. if count <= 0 then
  41. exit;
  42. FillChar (X,Count,value);
  43. end;
  44. {$endif not FPC_SYSTEM_HAS_FILLBYTE}
  45. {$ifndef FPC_SYSTEM_HAS_INDEXCHAR}
  46. {$define FPC_SYSTEM_HAS_INDEXCHAR}
  47. function memchr(const buf; b: sizeuint; len: cardinal): pointer; cdecl; external 'c';
  48. function IndexChar(Const buf;len:sizeint;b:char):sizeint;
  49. var
  50. res: pointer;
  51. begin
  52. if len = 0 then
  53. exit(-1);
  54. { simulate assembler implementations behaviour, which is expected }
  55. { fpc_pchar_to_ansistr in astrings.inc (interpret values < 0 as }
  56. { unsigned) }
  57. res := memchr(buf,longint(b),cardinal(len));
  58. if (res <> nil) then
  59. IndexChar := SizeInt(res-@buf)
  60. else
  61. IndexChar := -1;
  62. end;
  63. {$endif not FPC_SYSTEM_HAS_INDEXCHAR}
  64. {$ifndef FPC_SYSTEM_HAS_INDEXBYTE}
  65. {$define FPC_SYSTEM_HAS_INDEXBYTE}
  66. function IndexByte(Const buf;len:sizeint;b:byte):sizeint;{$ifdef SYSTEMINLINE}inline;{$endif}
  67. begin
  68. IndexByte:=IndexChar(buf,len,char(b));
  69. end;
  70. {$endif not FPC_SYSTEM_HAS_INDEXBYTE}
  71. {$ifndef FPC_SYSTEM_HAS_COMPARECHAR}
  72. {$define FPC_SYSTEM_HAS_COMPARECHAR}
  73. function memcmp_comparechar(Const buf1,buf2;len:sizeuint):longint; cdecl; external 'c' name 'memcmp';
  74. function CompareChar(Const buf1,buf2;len:sizeint):sizeint;
  75. var
  76. res: longint;
  77. begin
  78. if len <= 0 then
  79. exit(0);
  80. res := memcmp_comparechar(buf1,buf2,len);
  81. if res < 0 then
  82. CompareChar := -1
  83. else if res > 0 then
  84. CompareChar := 1
  85. else
  86. CompareChar := 0;
  87. end;
  88. {$endif not FPC_SYSTEM_HAS_COMPARECHAR}
  89. {$ifndef FPC_SYSTEM_HAS_COMPAREBYTE}
  90. {$define FPC_SYSTEM_HAS_COMPAREBYTE}
  91. function CompareByte(Const buf1,buf2;len:sizeint):sizeint;{$ifdef SYSTEMINLINE}inline;{$endif}
  92. begin
  93. CompareByte := CompareChar(buf1,buf2,len);
  94. end;
  95. {$endif not FPC_SYSTEM_HAS_COMPAREBYTE}
  96. {$ifndef FPC_SYSTEM_HAS_COMPARECHAR0}
  97. {$define FPC_SYSTEM_HAS_COMPARECHAR0}
  98. function strncmp_comparechar0(Const buf1,buf2;len:sizeuint):longint; cdecl; external 'c' name 'strncmp';
  99. function CompareChar0(Const buf1,buf2;len:sizeint):sizeint;{$ifdef SYSTEMINLINE}inline;{$endif}
  100. begin
  101. if len <= 0 then
  102. exit(0);
  103. strncmp_comparechar0(buf1,buf2,len);
  104. end;
  105. {$endif not FPC_SYSTEM_HAS_COMPARECHAR0}
  106. {$ifndef FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
  107. {$define FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
  108. function libc_pchar_length(p:pchar):sizeuint; cdecl; external 'c' name 'strlen';
  109. function fpc_pchar_length(p:pchar):longint;[public,alias:'FPC_PCHAR_LENGTH']; compilerproc;
  110. begin
  111. fpc_pchar_length:=libc_pchar_length(p);
  112. end;
  113. {$endif ndef FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}