Skip to content

Commit 9509584

Browse files
author
Alex Cole
committed
Fix ftouch.
1 parent be8c69c commit 9509584

File tree

5 files changed

+25
-39
lines changed

5 files changed

+25
-39
lines changed

YSI_Core/y_utils/y_utils_files.inc

+18-18
Original file line numberDiff line numberDiff line change
@@ -104,32 +104,32 @@ Optional plugins:
104104
* </remarks>
105105
*//*------------------------------------------------------------------------**/
106106

107-
#if !defined ftouch || defined y_utils_ftouch
108-
stock ftouch(const string:filename[])
107+
stock YSI_ftouch__(const string:filename[])
108+
{
109+
if (fexist(filename))
110+
{
111+
return 0;
112+
}
113+
else
109114
{
110-
if (fexist(filename))
115+
new
116+
File:f = fopen(filename, io_write);
117+
if (f)
111118
{
112-
return 0;
119+
fclose(f);
120+
return 1;
113121
}
114122
else
115123
{
116-
new
117-
File:f = fopen(filename, io_write);
118-
if (f)
119-
{
120-
fclose(f);
121-
return 1;
122-
}
123-
else
124-
{
125-
return -1;
126-
}
124+
return -1;
127125
}
128126
}
127+
}
129128

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

135135
/*-------------------------------------------------------------------------*//**

YSI_Players/y_users/y_users_ini.inc

+5-5
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ stock Player_IsRegistered(playerid)
275275

276276
HOOK__ OnYSIInit()
277277
{
278-
switch (ftouch(USER_FILE_PATH "index.YSI"))
278+
switch (YSI_ftouch__(USER_FILE_PATH "index.YSI"))
279279
{
280280
case -1:
281281
{
@@ -286,14 +286,14 @@ HOOK__ OnYSIInit()
286286
if (Player_CreateNewID())
287287
{
288288
// Don't need upgrades.
289-
if (ftouch(USER_FILE_PATH "y_users_v2_1.YSI") == -1)
289+
if (YSI_ftouch__(USER_FILE_PATH "y_users_v2_1.YSI") == -1)
290290
{
291291
Debug_Error("Could not touch upgrade file 1.");
292292
// Use "else" so we don't try do upgrade 2 without upgrade
293293
// 1. That would really mess up the files (that don't yet
294294
// exist, but could do).
295295
}
296-
else if (ftouch(USER_FILE_PATH "y_users_v2_2.YSI") == -1)
296+
else if (YSI_ftouch__(USER_FILE_PATH "y_users_v2_2.YSI") == -1)
297297
{
298298
Debug_Error("Could not touch upgrade file 2.");
299299
}
@@ -1255,7 +1255,7 @@ static stock Player_CreateNewID()
12551255
static stock Users_DoUpgrade0()
12561256
{
12571257
// Only ever do this upgrade once.
1258-
switch (ftouch(USER_FILE_PATH "y_users_v2_1.YSI"))
1258+
switch (YSI_ftouch__(USER_FILE_PATH "y_users_v2_1.YSI"))
12591259
{
12601260
case -1:
12611261
{
@@ -1371,7 +1371,7 @@ static stock Users_DoUpgrade0()
13711371
static stock Users_DoUpgrade1()
13721372
{
13731373
// Only ever do this upgrade once.
1374-
switch (ftouch(USER_FILE_PATH "y_users_v2_2.YSI"))
1374+
switch (YSI_ftouch__(USER_FILE_PATH "y_users_v2_2.YSI"))
13751375
{
13761376
// case 0: Already exists.
13771377
case -1:

YSI_Players/y_users/y_users_mysql.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ stock Player_IsRegistered(playerid)
261261

262262
HOOK__ OnYSIInit()
263263
{
264-
switch (ftouch(USER_FILE_PATH "index.YSI"))
264+
switch (YSI_ftouch__(USER_FILE_PATH "index.YSI"))
265265
{
266266
case -1:
267267
{

YSI_Storage/y_ini/y_ini_impl.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ static stock bool:INI_SetTag_(INI:file, const tag[])
988988
stock INI:INI_Open(const filename[])
989989
{
990990
Debug_Print3("INI:INI_Open called: \"%s\"", filename);
991-
if (ftouch(filename) == -1)
991+
if (YSI_ftouch__(filename) == -1)
992992
{
993993
Debug_Warning("INI_Open could not find or create file %s", filename);
994994
}

YSI_Storage/y_ini/y_ini_tests.inc

-14
Original file line numberDiff line numberDiff line change
@@ -951,25 +951,11 @@ public INI_PUB_Inl_(string:name[], string:value[])
951951
fclose(f);
952952
}
953953

954-
printf("a:");
955-
if ((f = fopen(MakeYINITestPath("test10.ini"), io_read)))
956-
{
957-
while (fread(f, str)) printf(str);
958-
fclose(f);
959-
}
960-
961954
new INI:i = INI_Open(MakeYINITestPath("test10.ini"));
962955
INI_SetTag(i, "tag_with_parent");
963956
INI_RemoveEntry(i, "value");
964957
INI_Close(i);
965958

966-
printf("b:");
967-
if ((f = fopen(MakeYINITestPath("test10.ini"), io_read)))
968-
{
969-
while (fread(f, str)) printf(str);
970-
fclose(f);
971-
}
972-
973959
f = fopen(MakeYINITestPath("test10.ini"), io_read);
974960
ASSERT(!!f);
975961
if (f)

0 commit comments

Comments
 (0)