liblinux++

A hosted C++ runtime without any libc.
git clone git://henryandlizzy.uk/liblinux++
Log | Files | Refs

sleep.cpp (528B)


      1 #include "linux.hpp"
      2 
      3 bool parse_digit(char c, uint64_t& out)
      4 {
      5 	if (c < '0' or '9' < c)
      6 		return false;
      7 
      8 	out = c - '0';
      9 	return true;
     10 }
     11 
     12 bool parse_u64(char const* p, uint64_t& out)
     13 {
     14 	if (!parse_digit(*p, out))
     15 		return false;
     16 
     17 	while (*++p)
     18 	{
     19 		uint64_t d;
     20 		if (not parse_digit(*p, d))
     21 			return false;
     22 		out = out * 10 + d;
     23 	}
     24 	return true;
     25 }
     26 
     27 int main(int argc, char* argv[])
     28 {
     29 	uint64_t n;
     30 	if (argc != 2 or not parse_u64(argv[1], n))
     31 		return 1;
     32 
     33 	timespec duration{(time_t)n, 0};
     34     *nanosleep(duration, nullptr);
     35 }