diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 4982ffa5899..8a4db10c843 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -152,6 +152,12 @@ int BLI_compare(struct direntry *entry1, struct direntry *entry2) } if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1); if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1); + + /* make sure "." and ".." are always first */ + if( strcmp(entry1->relname, ".")==0 ) return (-1); + if( strcmp(entry2->relname, ".")==0 ) return (1); + if( strcmp(entry1->relname, "..")==0 ) return (-1); + return (strcasecmp(entry1->relname,entry2->relname)); } diff --git a/source/blender/src/filesel.c b/source/blender/src/filesel.c index 4440ecaa86d..cb4e1681dc5 100644 --- a/source/blender/src/filesel.c +++ b/source/blender/src/filesel.c @@ -312,6 +312,12 @@ static int compare_name(const void *a1, const void *a2) } if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1); if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1); + + /* make sure "." and ".." are always first */ + if( strcmp(entry1->relname, ".")==0 ) return (-1); + if( strcmp(entry2->relname, ".")==0 ) return (1); + if( strcmp(entry1->relname, "..")==0 ) return (-1); + return (strcasecmp(entry1->relname,entry2->relname)); } @@ -334,12 +340,14 @@ static int compare_date(const void *a1, const void *a2) if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1); if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1); -/* - if ( entry1->s.st_ctime < entry2->s.st_ctime) return 1; - if ( entry1->s.st_ctime > entry2->s.st_ctime) return -1; -*/ + /* make sure "." and ".." are always first */ + if( strcmp(entry1->relname, ".")==0 ) return (-1); + if( strcmp(entry2->relname, ".")==0 ) return (1); + if( strcmp(entry1->relname, "..")==0 ) return (-1); + if ( entry1->s.st_mtime < entry2->s.st_mtime) return 1; if ( entry1->s.st_mtime > entry2->s.st_mtime) return -1; + else return strcasecmp(entry1->relname,entry2->relname); } @@ -362,6 +370,11 @@ static int compare_size(const void *a1, const void *a2) if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1); if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1); + /* make sure "." and ".." are always first */ + if( strcmp(entry1->relname, ".")==0 ) return (-1); + if( strcmp(entry2->relname, ".")==0 ) return (1); + if( strcmp(entry1->relname, "..")==0 ) return (-1); + if ( entry1->s.st_size < entry2->s.st_size) return 1; if ( entry1->s.st_size > entry2->s.st_size) return -1; else return strcasecmp(entry1->relname,entry2->relname);