Есть такой код
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
int main()
{
int actlen;
int hfile, hl;
char fname[] = "text.txt";
char buf[100] = "";
struct flock lock = {F_WRLCK,SEEK_SET, 0, 0};
printf("\033[4;30;45m\033[20;33HHello!\n");
printf("\033[21;33HLAB4: Block files\n");
fflush(stdout);
hfile = open(fname, O_RDWR, NULL);
if ( hfile == -1 )
{
if (errno == EACCES) printf("\033[22;33HFile access denied!\n");
else printf("\033[22;33HFile not found!\n");
printf("\033[0m");
return 1;
}
printf("\033[0m");
hl = fcntl(hfile, F_SETLK, &lock);
if (hl==-1)
{
printf("\033[2J\033[1;34;42m\033[1;24H");
printf("File lock not permitted! Wait...\n");
fcntl(hfile, F_SETLKW, &lock);
}
printf("\033[2J\033[1;31;44m\033[1;24H");
printf("File lock permitted! Please press <ENTER>.\n");
fflush(stdout);
getchar();
printf("\033[12;32H");
actlen = read(hfile, buf, 80);
write(1, buf, actlen);
printf("\033[0m");
printf("\nPress <Enter> for exit!\n");
fflush(stdout);
getchar();
lock.l_type=F_UNLCK;
if (fcntl(hfile, F_SETLK, &lock)==-1)
{
printf("File not unlocked!");
printf("\033[0m\033[2J");
close(hfile);
return 1;
}
printf("\033[0m\033[2J");
close(hfile);
}
Он под Linux.
Какие строки нужно поменять для Windows? Проблема в основном из за констант.