summaryrefslogtreecommitdiff
path: root/windows-NT/unistd.c
blob: 6ff09c89edfc4a79147583053d39ce42ed555a59 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * windows-NT/unitstd.c
 * POSIX/UNIX functions not provided by Win32 platform
 * and declared in <unistd.h> header file
 */

#include "unistd.h"

#include <stdio.h>
#include <conio.h>

#include <sys/socket.h>  /* This does: #include <windows.h> */

/* Please order functions by name if possible */



char *
getpass (const char *prompt)
{
    static char pwd_buf[128];
    size_t i;

    fputs (prompt, stderr);
    fflush (stderr);
    for (i = 0; i < sizeof (pwd_buf) - 1; ++i)
    {
	pwd_buf[i] = _getch ();
	if (pwd_buf[i] == '\r')
	    break;
    }
    pwd_buf[i] = '\0';
    fputs ("\n", stderr);
    return pwd_buf;
}



/* This is just a call to GetCurrentProcessID */
pid_t
getpid (void)
{
    return (pid_t) GetCurrentProcessId();
}



unsigned int sleep (unsigned seconds)
{
    Sleep (1000*seconds);
    return 0;
}



/*
 * Sleep at least some number of microseconds
 */
int usleep (useconds_t microseconds)
{
    if ( microseconds )
    {
	const useconds_t one_second = 1000000;
	struct timeval tv_delay;

	tv_delay.tv_sec = microseconds / one_second;
	tv_delay.tv_usec = microseconds % one_second;
	return select (0, NULL, NULL, NULL, &tv_delay);
    }
    return 0;
}