You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
803 B
C++
46 lines
803 B
C++
15 years ago
|
// lock.cpp : Defines the entry point for the console application.
|
||
|
//
|
||
|
|
||
|
#include "stdafx.h"
|
||
|
#include <nel/misc/types_nl.h>
|
||
|
#include <nel/misc/time_nl.h>
|
||
|
#include <nel/misc/common.h>
|
||
|
#include <stdio.h>
|
||
|
|
||
|
using namespace NLMISC;
|
||
|
|
||
|
int main(int argc, char* argv[])
|
||
|
{
|
||
|
if (argc <3)
|
||
|
{
|
||
|
printf ("lock.exe [filein] [fleout]\n\t");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// Random
|
||
|
srand ((int)CTime::getLocalTime ());
|
||
|
|
||
|
// Open the filein
|
||
|
while (1)
|
||
|
{
|
||
|
// Rename the file
|
||
|
if (rename(argv[1], argv[2]) == 0)
|
||
|
{
|
||
|
return 1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// Sleep..
|
||
|
printf ("Locked. Waiting for lock to be released\n");
|
||
|
uint sleepTime = (rand () * 5000) / RAND_MAX;
|
||
|
nlSleep (sleepTime);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Open the fileout
|
||
|
FILE *fileOut = fopen (argv[2], "w");
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|