Browse Source

Implement the _ttail_search_file_sorted() function

Telling if the logfile array is sorted
Yann Weber 7 years ago
parent
commit
5ccb971b71
2 changed files with 19 additions and 5 deletions
  1. 2
    1
      src/include/ttail_search_files.h
  2. 17
    4
      src/ttail_search_files.c

+ 2
- 1
src/include/ttail_search_files.h View File

@@ -59,7 +59,8 @@ int _ttail_search_closest_files_set_fsizes(ttail_t*);
59 59
  *
60 60
  *If not sorted attempt to sort them
61 61
  *@param ttail_t*
62
- *@return -1 not sorted 0 sorted
62
+ *@return -1 not sorted 0 sorted -3 error
63
+ *@todo checks
63 64
  */
64 65
 int _ttail_search_file_sorted(ttail_t*);
65 66
 

+ 17
- 4
src/ttail_search_files.c View File

@@ -113,17 +113,30 @@ int _ttail_search_closest_files_set_fsizes(ttail_t* t)
113 113
 int _ttail_search_file_sorted(ttail_t* t)
114 114
 {
115 115
 	/* files start & stop log tm, file start id = i*2 file stop = i*2+1 */
116
-	struct tm *ftm; 
116
+	struct tm *ftm;
117
+	size_t i;
117 118
 
118 119
 	ftm = malloc(sizeof(struct tm)*t->logfile_sz*2);
119 120
 	if(!ftm)
120 121
 	{
121 122
 		perror("Unable to allocate memory");
122
-		return -1;
123
+		return -3;
124
+	}
125
+	for(i=0; i<t->logfile_sz; i++)
126
+	{
127
+		_ttail_file_minmax(t, 0, ftm+(i*2));
128
+		if(i)
129
+		{
130
+			if(ttail_tm_cmp(ftm+((i-1)*2)+1, ftm+i*2) > 0)
131
+			{
132
+				/* not sorted */
133
+				free(ftm);
134
+				return -1;
135
+			}
136
+		}
123 137
 	}
124
-
125 138
 	free(ftm);
126
-	return -1;
139
+	return 0;
127 140
 }
128 141
 
129 142
 int _ttail_file_minmax(ttail_t* t, size_t id, struct tm tm[2])

Loading…
Cancel
Save