fixed Makefile for distribution package (which has no Makefile for graphics)
[rocksndiamonds.git] / src / libgame / misc.c
index 6d80620b99c61c1ebad5f5c5445c153ec6e5887d..c1e8eee4f9c492a11ba7829282c967a89b09e4b8 100644 (file)
@@ -427,7 +427,9 @@ int WaitUntilDelayReached(unsigned int *counter_var, unsigned int delay)
       break;
   }
 
-  if (*counter_var != 0 && actual_counter >= *counter_var + delay)
+  if (*counter_var != 0 &&
+      delay != 0 &&
+      actual_counter >= *counter_var + delay)
   {
     int lag = actual_counter - (*counter_var + delay);
     int delay2 = (delay + 1) / 2;
@@ -652,6 +654,23 @@ char *getBaseName(char *filename)
   return getStringCopy(getBaseNamePtr(filename));
 }
 
+char *getBaseNameNoSuffix(char *filename)
+{
+  char *basename = getStringCopy(getBaseNamePtr(filename));
+
+  // remove trailing suffix (separated by dot or hyphen)
+  if (basename[0] != '.' && basename[0] != '-')
+  {
+    if (strchr(basename, '.') != NULL)
+      *strchr(basename, '.') = '\0';
+
+    if (strchr(basename, '-') != NULL)
+      *strchr(basename, '-') = '\0';
+  }
+
+  return basename;
+}
+
 char *getBasePath(char *filename)
 {
   char *basepath = getStringCopy(filename);
@@ -1304,7 +1323,7 @@ void clear_mem(void *ptr, unsigned int size)
 /* various helper functions                                                  */
 /* ------------------------------------------------------------------------- */
 
-inline void swap_numbers(int *i1, int *i2)
+void swap_numbers(int *i1, int *i2)
 {
   int help = *i1;
 
@@ -1312,7 +1331,7 @@ inline void swap_numbers(int *i1, int *i2)
   *i2 = help;
 }
 
-inline void swap_number_pairs(int *x1, int *y1, int *x2, int *y2)
+void swap_number_pairs(int *x1, int *y1, int *x2, int *y2)
 {
   int help_x = *x1;
   int help_y = *y1;
@@ -2398,7 +2417,7 @@ DirectoryEntry *readDirectory(Directory *dir)
 
   dir->dir_entry->is_directory =
     (stat(dir->dir_entry->filename, &file_status) == 0 &&
-     (file_status.st_mode & S_IFMT) == S_IFDIR);
+     S_ISDIR(file_status.st_mode));
 
   return dir->dir_entry;
 }
@@ -2425,7 +2444,7 @@ boolean directoryExists(char *dir_name)
 
   struct stat file_status;
   boolean success = (stat(dir_name, &file_status) == 0 &&
-                    (file_status.st_mode & S_IFMT) == S_IFDIR);
+                    S_ISDIR(file_status.st_mode));
 
 #if defined(PLATFORM_ANDROID)
   if (!success)