cgeneric.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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:size_t); 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: size_t); 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_INDEXBYTE}
  37. {$define FPC_SYSTEM_HAS_INDEXBYTE}
  38. function memchr(const buf; b: cint; len: size_t): pointer; cdecl; external 'c';
  39. function IndexByte(Const buf;len:sizeint;b:byte):sizeint;{$ifdef SYSTEMINLINE}inline;{$endif}
  40. var
  41. res: pointer;
  42. begin
  43. if len = 0 then
  44. exit(-1);
  45. { simulate assembler implementations behaviour, which is expected }
  46. { fpc_pchar_to_ansistr in astrings.inc (interpret values < 0 as }
  47. { unsigned) }
  48. res := memchr(buf,cint(b),size_t(sizeuint(len)));
  49. if (res <> nil) then
  50. IndexByte := SizeInt(res-@buf)
  51. else
  52. IndexByte := -1;
  53. end;
  54. {$endif not FPC_SYSTEM_HAS_INDEXBYTE}
  55. {$ifndef FPC_SYSTEM_HAS_COMPAREBYTE}
  56. {$define FPC_SYSTEM_HAS_COMPAREBYTE}
  57. function memcmp_comparechar(Const buf1,buf2;len:size_t):cint; cdecl; external 'c' name 'memcmp';
  58. function CompareByte(Const buf1,buf2;len:sizeint):sizeint;{$ifdef SYSTEMINLINE}inline;{$endif}
  59. var
  60. res: longint;
  61. begin
  62. if len <= 0 then
  63. exit(0);
  64. res := memcmp_comparechar(buf1,buf2,len);
  65. if res < 0 then
  66. CompareByte := -1
  67. else if res > 0 then
  68. CompareByte := 1
  69. else
  70. CompareByte := 0;
  71. end;
  72. {$endif not FPC_SYSTEM_HAS_COMPAREBYTE}
  73. {$ifndef FPC_SYSTEM_HAS_COMPARECHAR0}
  74. {$define FPC_SYSTEM_HAS_COMPARECHAR0}
  75. function strncmp_comparechar0(Const buf1,buf2;len:size_t):longint; cdecl; external 'c' name 'strncmp';
  76. function CompareChar0(Const buf1,buf2;len:sizeint):sizeint;{$ifdef SYSTEMINLINE}inline;{$endif}
  77. begin
  78. if len <= 0 then
  79. exit(0);
  80. CompareChar0:=strncmp_comparechar0(buf1,buf2,len);
  81. end;
  82. {$endif not FPC_SYSTEM_HAS_COMPARECHAR0}
  83. {$ifndef FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
  84. {$define FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
  85. function libc_pchar_length(p:pchar):size_t; cdecl; external 'c' name 'strlen';
  86. function fpc_pchar_length(p:pchar):longint;[public,alias:'FPC_PCHAR_LENGTH']; compilerproc;
  87. begin
  88. if assigned(p) then
  89. fpc_pchar_length:=libc_pchar_length(p)
  90. else
  91. fpc_pchar_length:=0;
  92. end;
  93. {$endif ndef FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}