Changeset 1750
- Timestamp:
- 07/12/10 00:51:02 (14 years ago)
- Files:
-
- trunk/phobos/std/stdio.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/std/stdio.d
r1725 r1750 80 80 alias __fp_unlock FUNLOCK; 81 81 82 82 alias setmode _setmode; 83 83 enum _O_BINARY = 0x8000; 84 84 int _fileno(FILE* f) { return f._file; } 85 85 } 86 86 else version (GCC_IO) 87 87 { 88 88 /* ** 89 89 * Gnu under-the-hood C I/O functions; see 90 * http:// www.gnu.org/software/libc/manual/html_node/I_002fO-on-Streams.html#I_002fO-on-Streams90 * http://gnu.org/software/libc/manual/html_node/I_002fO-on-Streams.html 91 91 */ 92 //private import std.c.linux.linux;93 92 private import core.sys.posix.stdio; 94 93 extern (C) 95 94 { 96 95 int fputc_unlocked(int, _iobuf*); 97 96 int fputwc_unlocked(wchar_t, _iobuf*); 98 97 int fgetc_unlocked(_iobuf*); 99 98 int fgetwc_unlocked(_iobuf*); 100 99 void flockfile(FILE*); 101 100 void funlockfile(FILE*); 102 101 ssize_t getline(char**, size_t*, FILE*); … … 615 614 616 615 /** 617 616 If the file is not opened, throws an exception. Otherwise, writes its 618 617 arguments in text format to the file, according to the format in the 619 618 first argument. */ 620 619 void writef(S...)(S args)// if (isSomeString!(S[0])) 621 620 { 622 621 assert(p); 623 622 assert(p.handle); 624 623 static assert(isSomeString!(S[0]), errorMessage); 625 auto w = lockingTextWriter ;624 auto w = lockingTextWriter(); 626 625 std.format.formattedWrite(w, args); 627 626 } 628 627 629 628 /** 630 629 Same as writef, plus adds a newline. */ 631 630 void writefln(S...)(S args) 632 631 { 633 632 static assert(isSomeString!(S[0]), errorMessage); 634 633 auto w = lockingTextWriter; 635 634 std.format.formattedWrite(w, args); … … 1482 1481 f.writefln("Hello, %s world number %s!", "nice", 42); 1483 1482 f.close; 1484 1483 version (Windows) 1485 1484 assert(cast(char[]) std.file.read(file) == 1486 1485 "Hello, nice world number 42!\r\n"); 1487 1486 else 1488 1487 assert(cast(char[]) std.file.read(file) == 1489 1488 "Hello, nice world number 42!\n", 1490 1489 cast(char[]) std.file.read(file)); 1491 1490 // test write on stdout 1492 auto saveStdout = stdout;1493 scope(exit) stdout = saveStdout;1494 stdout.open(file, "w");1495 assert(stdout.isOpen);1496 writefln("Hello, %s world number %s!", "nice", 42);1497 foreach (F ; TypeTuple!(ifloat, idouble, ireal))1498 {1499 F a = 5i;1500 F b = a % 2;1501 writeln(b);1502 }1503 stdout.close;1504 auto read = cast(char[]) std.file.read(file);1505 version (Windows)1506 assert(read == "Hello, nice world number 42!\r\n1\r\n1\r\n1\r\n", read);1507 else1508 assert(read == "Hello, nice world number 42!\n1\n1\n1\n", "["~read~"]");1491 // auto saveStdout = stdout; 1492 // scope(exit) stdout = saveStdout; 1493 // stdout.open(file, "w"); 1494 // assert(stdout.isOpen); 1495 // writefln("Hello, %s world number %s!", "nice", 42); 1496 // foreach (F ; TypeTuple!(ifloat, idouble, ireal)) 1497 // { 1498 // F a = 5i; 1499 // F b = a % 2; 1500 // writeln(b); 1501 // } 1502 // stdout.close; 1503 // auto read = cast(char[]) std.file.read(file); 1504 // version (Windows) 1505 // assert(read == "Hello, nice world number 42!\r\n1\r\n1\r\n1\r\n", read); 1506 // else 1507 // assert(read == "Hello, nice world number 42!\n1\n1\n1\n", "["~read~"]"); 1509 1508 } 1510 1509 1511 1510 /** 1512 1511 * Formatted read one line from stdin. 1513 1512 */ 1514 1513 void readf(A...)(in char[] format, A args) 1515 1514 { 1516 1515 return stdin.readf(format, args); 1517 1516 } 1518 1517
