#include
#include
static void
file_cleanup(int *fd)
{
printf("close file descriptor.\n");
if (*fd >= 0)
close(*fd);
}
int
main(void)
{
int fd __attribute__ ((__cleanup__(file_cleanup)));
char *msg = "hello, world.\n";
if ((fd = open("/dev/tty", O_RDWR)) < 0)
{
perror("/dev/tty");
return 1;
}
write(fd, msg, strlen(msg));
return 0;
}
阅读(1102) | 评论(0) | 转发(0) |