File: pre.cpp

package info (click to toggle)
mymake 2.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 672 kB
  • sloc: cpp: 5,688; lisp: 300; ansic: 195; sh: 86; makefile: 32
file content (48 lines) | stat: -rw-r--r-- 789 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <sstream>

#if defined(_WIN32)
#include <Windows.h>

void work() {
	Sleep(500);
}

#else
#include <unistd.h>

void work() {
	usleep(500 * 1000);
}

#endif


// Outputting a lot of text when being run as a pre-build step, or elsewhere can cause some output to go missing.
const int lines = 100;


int main(int argc, const char *argv[]) {
	(void)argv;

	// Simulate working hard...
	work();

	// Make a large buffer and output everything at once!
	std::ostringstream out;
	for (int i = 0; i < lines; i++)
		out << "Line #" << i << std::endl;

	out << "Done!" << std::endl;

	// Turn of buffering:
	setvbuf(stdout, 0, _IONBF, 10*4096);
	std::cout << out.str();
	std::cout.flush();

	// Simulate failure if asked to do so.
	if (argc > 1)
		return 1;

	return 0;
}