[mw-devel] [Git][arthur/mw][master] Use readdir instead of readdir_r

Andrew Price welshbyte at sucs.org
Mon Jan 23 13:00:54 GMT 2017


Andrew Price pushed to branch master at Justin Mitchell / mw


Commits:
49b1776e by Andrew Price at 2017-01-23T13:00:55+00:00
Use readdir instead of readdir_r

Fixes:

  servsock.c: In function ‘migrate_old_folders’:
  servsock.c:684:2: error: ‘readdir_r’ is deprecated [-Werror=deprecated-declarations]
    while (readdir_r(dirp, &entry, &dp) == 0) {
    ^~~~~

- - - - -


1 changed file:

- src/server/servsock.c


Changes:

=====================================
src/server/servsock.c
=====================================
--- a/src/server/servsock.c
+++ b/src/server/servsock.c
@@ -655,7 +655,7 @@ void migrate_old_folders(void)
 	int dfd;
 	DIR *dirp;
 	unsigned i;
-	struct dirent entry, *dp;
+	struct dirent *entry;
 	const char *bbdirs[] = {
 		FOL_IDX_DIR,
 		FOL_IDX_DIR"/"FOL_NEW,
@@ -681,52 +681,50 @@ void migrate_old_folders(void)
 		return;
 	}
 	dfd = dirfd(dirp);
-	while (readdir_r(dirp, &entry, &dp) == 0) {
+	while ((entry = readdir(dirp)) != NULL) {
 		char *end, *path = NULL;
 
-		if (dp == NULL)
-			break;
-		if ((end = has_suffix(entry.d_name, ".t.t"))) {
+		if ((end = has_suffix(entry->d_name, ".t.t"))) {
 			*end = '\0';
-			asprintf(&path, FOL_TXT_DIR"/"FOL_NEW"/%s", entry.d_name);
+			asprintf(&path, FOL_TXT_DIR"/"FOL_NEW"/%s", entry->d_name);
 			*end = '.';
-			printf("Migrating folder '%s' to '%s'\n", entry.d_name, path);
-			renameat(dfd, entry.d_name, dfd, path);
+			printf("Migrating folder '%s' to '%s'\n", entry->d_name, path);
+			renameat(dfd, entry->d_name, dfd, path);
 		}
-		else if ((end = has_suffix(entry.d_name, ".i.t"))) {
+		else if ((end = has_suffix(entry->d_name, ".i.t"))) {
 			*end = '\0';
-			asprintf(&path, FOL_IDX_DIR"/"FOL_NEW"/%s", entry.d_name);
+			asprintf(&path, FOL_IDX_DIR"/"FOL_NEW"/%s", entry->d_name);
 			*end = '.';
-			printf("Migrating folder '%s' to '%s'\n", entry.d_name, path);
-			renameat(dfd, entry.d_name, dfd, path);
+			printf("Migrating folder '%s' to '%s'\n", entry->d_name, path);
+			renameat(dfd, entry->d_name, dfd, path);
 		}
-		else if ((end = has_suffix(entry.d_name, ".i.m"))) {
+		else if ((end = has_suffix(entry->d_name, ".i.m"))) {
 			*end = '\0';
-			asprintf(&path, FOL_IDX_DIR"/"FOL_MOD"/%s", entry.d_name);
+			asprintf(&path, FOL_IDX_DIR"/"FOL_MOD"/%s", entry->d_name);
 			*end = '.';
-			printf("Migrating folder '%s' to '%s'\n", entry.d_name, path);
-			renameat(dfd, entry.d_name, dfd, path);
+			printf("Migrating folder '%s' to '%s'\n", entry->d_name, path);
+			renameat(dfd, entry->d_name, dfd, path);
 		}
-		else if ((end = has_suffix(entry.d_name, ".t.m"))) {
+		else if ((end = has_suffix(entry->d_name, ".t.m"))) {
 			*end = '\0';
-			asprintf(&path, FOL_TXT_DIR"/"FOL_MOD"/%s", entry.d_name);
+			asprintf(&path, FOL_TXT_DIR"/"FOL_MOD"/%s", entry->d_name);
 			*end = '.';
-			printf("Migrating folder '%s' to '%s'\n", entry.d_name, path);
-			renameat(dfd, entry.d_name, dfd, path);
+			printf("Migrating folder '%s' to '%s'\n", entry->d_name, path);
+			renameat(dfd, entry->d_name, dfd, path);
 		}
-		else if ((end = has_suffix(entry.d_name, ".i"))) {
+		else if ((end = has_suffix(entry->d_name, ".i"))) {
 			*end = '\0';
-			asprintf(&path, FOL_IDX_DIR"/%s", entry.d_name);
+			asprintf(&path, FOL_IDX_DIR"/%s", entry->d_name);
 			*end = '.';
-			printf("Migrating folder '%s' to '%s'\n", entry.d_name, path);
-			renameat(dfd, entry.d_name, dfd, path);
+			printf("Migrating folder '%s' to '%s'\n", entry->d_name, path);
+			renameat(dfd, entry->d_name, dfd, path);
 		}
-		else if ((end = has_suffix(entry.d_name, ".t"))) {
+		else if ((end = has_suffix(entry->d_name, ".t"))) {
 			*end = '\0';
-			asprintf(&path, FOL_TXT_DIR"/%s", entry.d_name);
+			asprintf(&path, FOL_TXT_DIR"/%s", entry->d_name);
 			*end = '.';
-			printf("Migrating folder '%s' to '%s'\n", entry.d_name, path);
-			renameat(dfd, entry.d_name, dfd, path);
+			printf("Migrating folder '%s' to '%s'\n", entry->d_name, path);
+			renameat(dfd, entry->d_name, dfd, path);
 		}
 		if (path != NULL)
 			free(path);



View it on GitLab: https://projects.sucs.org/arthur/mw/commit/49b1776eed49999cf47209013856e3bcfe8034f8
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20170123/60522c09/attachment-0001.html>


More information about the mw-devel mailing list