[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MiNT] Fopen("NUL:", 0) returns -33 (ENOENT)



Hi,

There is a bug in filesys.c, which has only some generic code to translate device file names like NUL:, AUX: etc. to mint device filenames. It works by changing the actual looked up name to u:\dev\xxx, where 'xxx' is replace by the first 3 characters of the original filename. This works for CON:, AUX: and PRN:, but not for NUL: (where the actual filename is u:\dev\null) and MID: (u:\dev\midi), causing Fopen() to fail with error -ENOENT. I attached a patch to fix this.

Greetings,
   Thorsten
--- filesys.c.orig	2013-10-12 17:29:30.000000000 +0200
+++ filesys.c	2015-01-29 19:41:51.405000020 +0100
@@ -731,7 +731,7 @@
 relpath2cookie(struct proc *p, fcookie *relto, const char *path, char *lastname,
 	       fcookie *res, int depth)
 {
-	static char newpath[16] = "U:\\DEV\\";
+	char newpath[16];
 
 	struct cwd *cwd = p->p_cwd;
 
@@ -788,7 +788,27 @@
 	if (strlen (path) == 4 && path[3] == ':')
 # endif
 	{
-		strncpy (newpath+7, path, 3);
+		strcpy(newpath, "U:\\DEV\\");
+		newpath[7] = path[0];
+		newpath[8] = path[1];
+		newpath[9] = path[2];
+		newpath[10] = '\0';
+		if ((path[0] == 'N' || path[0] == 'n') &&
+		    (path[1] == 'U' || path[1] == 'u') &&
+		    (path[2] == 'L' || path[2] == 'l'))
+		{
+			/* the device file is u:\dev\null */
+			newpath[10] = 'l';
+			newpath[11] = '\0';
+		} else
+		if ((path[0] == 'M' || path[0] == 'm') &&
+		    (path[1] == 'I' || path[1] == 'i') &&
+		    (path[2] == 'D' || path[2] == 'd'))
+		{
+			/* the device file is u:\dev\midi */
+			newpath[10] = 'i';
+			newpath[11] = '\0';
+		}
 		path = newpath;
 	}