1111
1212module rt.cover ;
1313
14+ import core.internal.utf ;
1415import core.internal.util.math : max, min;
16+ import core.stdc.stdio : EOF , fclose, fgetc, FILE , fileno, fprintf, fread, fseek, ftell, printf, SEEK_END , SEEK_SET ,
17+ stderr;
18+ import core.stdc.stdlib : exit, EXIT_FAILURE ;
1519
16- private
20+ version ( Windows )
1721{
18- version (Windows )
19- {
20- import core.sys.windows.basetsd /+ : HANDLE+/ ;
21- import core.sys.windows.winbase /+ : LOCKFILE_EXCLUSIVE_LOCK, LockFileEx, OVERLAPPED, SetEndOfFile+/ ;
22- }
23- else version (Posix )
24- {
25- import core.sys.posix.fcntl : O_CREAT , O_RDWR , open, S_IRGRP , S_IROTH , S_IRUSR , S_IWGRP , S_IWOTH , S_IWUSR ;
26- import core.sys.posix.unistd : F_LOCK , ftruncate, lockf;
27- }
28- import core.internal.utf ;
29- import core.stdc.config : c_long;
30- import core.stdc.stdio ;
31- import core.stdc.stdlib ;
22+ import core.stdc.stdio : _fdopen, _get_osfhandle, _O_BINARY, _O_CREAT, _O_RDWR, _S_IREAD, _S_IWRITE, _wopen;
23+ import core.sys.windows.basetsd ;
24+ import core.sys.windows.winbase ;
25+ }
26+ else version (Posix )
27+ {
28+ import core.stdc.stdio : fopen;
29+ import core.sys.posix.fcntl : O_CREAT , O_RDWR , open, S_IRGRP , S_IROTH , S_IRUSR , S_IWGRP , S_IWOTH , S_IWUSR ;
30+ import core.sys.posix.unistd : F_LOCK , ftruncate, lockf;
31+ }
32+ else
33+ static assert (0 , " Unsupported platform" );
3234
35+ private
36+ {
3337 struct BitArray
3438 {
3539 size_t len;
@@ -321,14 +325,14 @@ shared static ~this()
321325
322326 version (Windows )
323327 SetEndOfFile(handle(fileno(flst)));
324- else
328+ else version ( Posix )
325329 ftruncate(fileno(flst), ftell (flst));
326330 }
327331}
328332
329333uint digits (uint number)
330334{
331- import core.stdc.math ;
335+ import core.stdc.math : floor, log10 ;
332336 return number ? cast (uint )floor(log10(number)) + 1 : 1 ;
333337}
334338
@@ -457,16 +461,14 @@ string chomp( string str, string delim = null )
457461// open/create file for read/write, pointer at beginning
458462FILE * openOrCreateFile (string name)
459463{
460- import core.internal.utf : toUTF16z;
461-
462464 version (Windows )
463465 immutable fd = _wopen(toUTF16z(name), _O_RDWR | _O_CREAT | _O_BINARY, _S_IREAD | _S_IWRITE);
464- else
466+ else version ( Posix )
465467 immutable fd = open((name ~ ' \0 ' ).ptr, O_RDWR | O_CREAT , S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
466468 S_IROTH | S_IWOTH );
467469 version (CRuntime_Microsoft )
468470 alias fdopen = _fdopen;
469- version (Posix )
471+ else version (Posix )
470472 import core.sys.posix.stdio : fdopen;
471473 return fdopen (fd, " r+b" );
472474}
@@ -492,8 +494,6 @@ void lockFile(int fd)
492494 // exclusively lock first byte
493495 LockFileEx(handle(fd), LOCKFILE_EXCLUSIVE_LOCK , 0 , 1 , 0 , &off);
494496 }
495- else
496- static assert (0 , " unimplemented" );
497497}
498498
499499bool readFile (FILE * file, ref char [] buf)
@@ -520,11 +520,9 @@ version (Windows) extern (C) nothrow @nogc FILE* _wfopen(scope const wchar* file
520520
521521bool readFile (string name, ref char [] buf)
522522{
523- import core.internal.utf : toUTF16z;
524-
525523 version (Windows )
526524 auto file = _wfopen(toUTF16z(name), " rb" w.ptr);
527- else
525+ else version ( Posix )
528526 auto file = fopen((name ~ ' \0 ' ).ptr, " rb" .ptr);
529527 if (file is null ) return false ;
530528 scope (exit) fclose (file);
0 commit comments