Makefile Create / Select timeout setting behaves differently on Unix and Linux
Makefile Create
- Definition
<Target>: <Dependencies> <Recipe>
- Base
app.out: main.o foo.o bar.o gcc -o app.out main.o foo.o bar.o main.o: foo.h bar.h main.c foo.o: foo.h foo.c bar.o: bar.h bar.c
- Use Args
CC=gcc CFLAGS=-g -Wall OBJS=main.o foo.o bar.o TARGET=app.out all: $(TARGET) $(TARGET): $(OBJS) $(CC) -o $@ $^ clean: rm -f *.o rm -f $(TARGET)
$@ = Current Block $(TARGET) $^ = Current Block Dependencies $? = Current Block Changed Dependencies
Select timeout setting behaves differently on Unix and Linux
On Linux, select() modifies timeout to reflect the amount of time not slept; most other implementations do not do this. (POSIX.1 permits either behavior.) This causes problems both when Linux code which reads timeout is ported to other operating systems, and when code is ported to Linux that reuses a struct timeval for multiple select() in a loop without reinitializing it. Consider timeout to be undefined after select() returns.
/** Unix **/
struct timeval tv.tv_sec = tv_sec;
tv.tv_usec = tv_usec;
while (1)
{
select(fd_max,fd_set,NULL,NULL,tv);
}
/** Linux **/
while (1)
{
struct timeval tv.tv_sec = tv_sec;
tv.tv_usec = tv_usec;
select(fd_max,fd_set,NULL,NULL,tv);
}