syspch.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. {
  2. *********************************************************************
  3. $Id$
  4. Copyright (C) 1997, 1998 Gertjan Schouten
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. *********************************************************************
  17. System Utilities For Free Pascal
  18. }
  19. { PChar functions }
  20. type
  21. pbyte = ^byte;
  22. CharArray = array[0..0] of char;
  23. { Processor dependent part, shared withs strings unit }
  24. {$IFNDEF VIRTUALPASCAL} // in system there
  25. {$i strings.inc }
  26. {$ENDIF}
  27. { Read generic string functions that are not implemented for the processor }
  28. {$i genstr.inc}
  29. { Processor independent part, shared with strings unit }
  30. {$i stringsi.inc }
  31. { StrPas converts a PChar to a pascal string }
  32. function StrPas(Str: PChar): string;
  33. begin
  34. Result:=Str;
  35. end ;
  36. { StrAlloc allocates a buffer of Size + 4
  37. the size of the allocated buffer is stored at result - 4
  38. StrDispose should be used to destroy the buffer }
  39. function StrAlloc(Size: cardinal): PChar;
  40. begin
  41. inc(size,sizeof(cardinal));
  42. getmem(result,size);
  43. cardinal(pointer(result)^):=size;
  44. inc(result,sizeof(cardinal));
  45. end;
  46. { Allocates a new string using StrAlloc, you need StrDispose to dispose the
  47. string }
  48. function strnew(p : pchar) : pchar;
  49. var
  50. len : longint;
  51. begin
  52. Result:=nil;
  53. if (p=nil) or (p^=#0) then
  54. exit;
  55. len:=strlen(p)+1;
  56. Result:=StrAlloc(Len);
  57. if Result<>nil then
  58. strmove(Result,p,len);
  59. end;
  60. { StrPCopy copies the pascal string Source to Dest and returns Dest }
  61. function StrPCopy(Dest: PChar; Source: string): PChar;
  62. begin
  63. result := StrMove(Dest, PChar(Source), length(Source)+1);
  64. end ;
  65. { StrPLCopy copies MaxLen or less characters from the pascal string
  66. Source to Dest and returns Dest }
  67. function StrPLCopy(Dest: PChar; Source: string; MaxLen: SizeUInt): PChar;
  68. var Count: SizeUInt;
  69. begin
  70. result := Dest;
  71. if (Result <> Nil) and (MaxLen <> 0) then begin
  72. Count := Length(Source);
  73. if Count > MaxLen then
  74. Count := MaxLen;
  75. StrMove(Dest, PChar(Source), Count);
  76. CharArray(result^)[Count] := #0; { terminate ! }
  77. end ;
  78. end ;
  79. { StrDispose clears the memory allocated with StrAlloc }
  80. procedure StrDispose(Str: PChar);
  81. begin
  82. if (Str <> Nil) then
  83. begin
  84. dec(Str,sizeof(cardinal));
  85. Freemem(str,cardinal(pointer(str)^));
  86. end;
  87. end;
  88. { StrBufSize returns the amount of memory allocated for pchar Str allocated with StrAlloc }
  89. function StrBufSize(Str: PChar): SizeUInt;
  90. begin
  91. if Str <> Nil then
  92. result := SizeUInt(pointer(Str - SizeOf(SizeUInt))^)-sizeof(SizeUInt)
  93. else
  94. result := 0;
  95. end ;
  96. {
  97. $Log$
  98. Revision 1.3 2004-05-01 23:55:18 peter
  99. * replace strlenint with sizeint
  100. Revision 1.2 2004/02/20 22:15:16 florian
  101. + x86_64 dependend sysutils part added
  102. * some 64 bit adaptions
  103. Revision 1.1 2003/10/06 21:01:06 peter
  104. * moved classes unit to rtl
  105. Revision 1.8 2003/09/06 21:52:24 marco
  106. * commited.
  107. Revision 1.7 2003/09/01 20:46:59 peter
  108. * small fixes for sparc
  109. Revision 1.6 2002/09/07 16:01:22 peter
  110. * old logs removed and tabs fixed
  111. Revision 1.5 2002/08/01 16:53:14 jonas
  112. * fix for StrPas() by Sergey Korshunoff <[email protected]> (merged)
  113. }