Commit 777899a6 authored by unknown's avatar unknown

improved mapping from numerical open codes to string fopen codes.

This was necessary because the old code would return 
"w+" for O_RDONLY|O_SHARE for example.


mysys/my_fopen.c:
  improved mapping from numerical open codes to string fopen codes.
parent 31aad78f
...@@ -158,32 +158,52 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags) ...@@ -158,32 +158,52 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags)
DBUG_RETURN(fd); DBUG_RETURN(fd);
} /* my_fdopen */ } /* my_fdopen */
/*
make_ftype
Make a filehandler-open-typestring from ordinary inputflags
/* Make a filehandler-open-typestring from ordinary inputflags */ Note: This routine attempts to find the best possible match
between a numeric option and a string option that could be
fed to fopen. There is not a 1 to 1 mapping between the two.
r == O_RDONLY
w == O_WRONLY|O_TRUNC|O_CREAT
a == O_WRONLY|O_APPEND|O_CREAT
r+ == O_RDWR
w+ == O_RDWR|O_TRUNC|O_CREAT
a+ == O_RDWR|O_APPEND|O_CREAT
*/
static void make_ftype(register my_string to, register int flag) static void make_ftype(register my_string to, register int flag)
{ {
#if FILE_BINARY /* If we have binary-files */ #if FILE_BINARY
/* If we have binary-files */
reg3 int org_flag=flag; reg3 int org_flag=flag;
#endif #endif
flag&= ~FILE_BINARY; /* remove binary bit */ flag&= ~FILE_BINARY; /* remove binary bit */
if (flag == O_RDONLY)
*to++= 'r'; /* check some possible invalid combinations */
else if (flag == O_WRONLY) DBUG_ASSERT(flag & (O_TRUNC|O_APPEND) != O_TRUNC|O_APPEND);
*to++= 'w';
else if (flag & (O_RDONLY|O_WRONLY) == O_WRONLY)
{ /* Add '+' after theese */ *to++= (flag & O_TRUNC) ? 'w' : 'a';
if (flag == O_RDWR) else if (flag & O_RDWR)
{
/* Add '+' after theese */
if (flag & O_TRUNC)
*to++= 'w';
else if (flag & O_APPEND)
*to++= 'a';
else
*to++= 'r'; *to++= 'r';
else if (flag & O_APPEND) *to++= '+';
*to++= 'a'; }
else else
*to++= 'w'; /* Create file */ *to++= 'r';
*to++= '+';
} #if FILE_BINARY /* If we have binary-files */
#if FILE_BINARY /* If we have binary-files */ if (org_flag & FILE_BINARY)
if (org_flag & FILE_BINARY)
*to++='b'; *to++='b';
#endif #endif
*to='\0'; *to='\0';
} /* make_ftype */ } /* make_ftype */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment