Skip to content

Commit

Permalink
Fix ftouch.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Cole committed Nov 12, 2023
1 parent be8c69c commit 9509584
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 39 deletions.
36 changes: 18 additions & 18 deletions YSI_Core/y_utils/y_utils_files.inc
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,32 @@ Optional plugins:
* </remarks>
*//*------------------------------------------------------------------------**/

#if !defined ftouch || defined y_utils_ftouch
stock ftouch(const string:filename[])
stock YSI_ftouch__(const string:filename[])
{
if (fexist(filename))
{
return 0;
}
else
{
if (fexist(filename))
new
File:f = fopen(filename, io_write);
if (f)
{
return 0;
fclose(f);
return 1;
}
else
{
new
File:f = fopen(filename, io_write);
if (f)
{
fclose(f);
return 1;
}
else
{
return -1;
}
return -1;
}
}
}

static stock y_utils_ftouch()
{
}
#if !defined ftouch
// Turns out there's a bug in open.mp's `ftouch`, for now.
#define ftouch( YSI_ftouch__(
#define _ALS_ftouch
#endif

/*-------------------------------------------------------------------------*//**
Expand Down
10 changes: 5 additions & 5 deletions YSI_Players/y_users/y_users_ini.inc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ stock Player_IsRegistered(playerid)

HOOK__ OnYSIInit()
{
switch (ftouch(USER_FILE_PATH "index.YSI"))
switch (YSI_ftouch__(USER_FILE_PATH "index.YSI"))
{
case -1:
{
Expand All @@ -286,14 +286,14 @@ HOOK__ OnYSIInit()
if (Player_CreateNewID())
{
// Don't need upgrades.
if (ftouch(USER_FILE_PATH "y_users_v2_1.YSI") == -1)
if (YSI_ftouch__(USER_FILE_PATH "y_users_v2_1.YSI") == -1)
{
Debug_Error("Could not touch upgrade file 1.");
// Use "else" so we don't try do upgrade 2 without upgrade
// 1. That would really mess up the files (that don't yet
// exist, but could do).
}
else if (ftouch(USER_FILE_PATH "y_users_v2_2.YSI") == -1)
else if (YSI_ftouch__(USER_FILE_PATH "y_users_v2_2.YSI") == -1)
{
Debug_Error("Could not touch upgrade file 2.");
}
Expand Down Expand Up @@ -1255,7 +1255,7 @@ static stock Player_CreateNewID()
static stock Users_DoUpgrade0()
{
// Only ever do this upgrade once.
switch (ftouch(USER_FILE_PATH "y_users_v2_1.YSI"))
switch (YSI_ftouch__(USER_FILE_PATH "y_users_v2_1.YSI"))
{
case -1:
{
Expand Down Expand Up @@ -1371,7 +1371,7 @@ static stock Users_DoUpgrade0()
static stock Users_DoUpgrade1()
{
// Only ever do this upgrade once.
switch (ftouch(USER_FILE_PATH "y_users_v2_2.YSI"))
switch (YSI_ftouch__(USER_FILE_PATH "y_users_v2_2.YSI"))
{
// case 0: Already exists.
case -1:
Expand Down
2 changes: 1 addition & 1 deletion YSI_Players/y_users/y_users_mysql.inc
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ stock Player_IsRegistered(playerid)

HOOK__ OnYSIInit()
{
switch (ftouch(USER_FILE_PATH "index.YSI"))
switch (YSI_ftouch__(USER_FILE_PATH "index.YSI"))
{
case -1:
{
Expand Down
2 changes: 1 addition & 1 deletion YSI_Storage/y_ini/y_ini_impl.inc
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ static stock bool:INI_SetTag_(INI:file, const tag[])
stock INI:INI_Open(const filename[])
{
Debug_Print3("INI:INI_Open called: \"%s\"", filename);
if (ftouch(filename) == -1)
if (YSI_ftouch__(filename) == -1)
{
Debug_Warning("INI_Open could not find or create file %s", filename);
}
Expand Down
14 changes: 0 additions & 14 deletions YSI_Storage/y_ini/y_ini_tests.inc
Original file line number Diff line number Diff line change
Expand Up @@ -951,25 +951,11 @@ public INI_PUB_Inl_(string:name[], string:value[])
fclose(f);
}

printf("a:");
if ((f = fopen(MakeYINITestPath("test10.ini"), io_read)))
{
while (fread(f, str)) printf(str);
fclose(f);
}

new INI:i = INI_Open(MakeYINITestPath("test10.ini"));
INI_SetTag(i, "tag_with_parent");
INI_RemoveEntry(i, "value");
INI_Close(i);

printf("b:");
if ((f = fopen(MakeYINITestPath("test10.ini"), io_read)))
{
while (fread(f, str)) printf(str);
fclose(f);
}

f = fopen(MakeYINITestPath("test10.ini"), io_read);
ASSERT(!!f);
if (f)
Expand Down

0 comments on commit 9509584

Please sign in to comment.