add a new function, SECU_TextFileToItem, for reading text files.
git-svn-id: svn://10.0.0.236/trunk@80875 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
4ff87894d0
commit
e7afcf22fd
@ -1027,6 +1027,40 @@ secu_StdinToItem(SECItem *dst)
|
||||
|
||||
SECStatus
|
||||
SECU_FileToItem(SECItem *dst, PRFileDesc *src)
|
||||
{
|
||||
PRFileInfo info;
|
||||
PRInt32 numBytes;
|
||||
PRStatus prStatus;
|
||||
|
||||
if (src == PR_STDIN)
|
||||
return secu_StdinToItem(dst);
|
||||
|
||||
prStatus = PR_GetOpenFileInfo(src, &info);
|
||||
|
||||
if (prStatus != PR_SUCCESS) {
|
||||
PORT_SetError(SEC_ERROR_IO);
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
/* XXX workaround for 3.1, not all utils zero dst before sending */
|
||||
dst->data = 0;
|
||||
if (!SECITEM_AllocItem(NULL, dst, info.size))
|
||||
goto loser;
|
||||
|
||||
numBytes = PR_Read(src, dst->data, info.size);
|
||||
if (numBytes != info.size) {
|
||||
PORT_SetError(SEC_ERROR_IO);
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return SECSuccess;
|
||||
loser:
|
||||
SECITEM_FreeItem(dst, PR_FALSE);
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
SECStatus
|
||||
SECU_TextFileToItem(SECItem *dst, PRFileDesc *src)
|
||||
{
|
||||
PRFileInfo info;
|
||||
PRInt32 numBytes;
|
||||
@ -1053,11 +1087,10 @@ SECU_FileToItem(SECItem *dst, PRFileDesc *src)
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* XXX workaround for 3.1, function needs to take a "chop" arg
|
||||
while (buf[numBytes-1] == '\r' ||
|
||||
buf[numBytes-1] == '\n' ||
|
||||
buf[numBytes-1] == '\0') numBytes--;
|
||||
*/
|
||||
if (buf[numBytes-1] == '\n') numBytes--;
|
||||
#ifdef _WINDOWS
|
||||
if (buf[numBytes-1] == '\r') numBytes--;
|
||||
#endif
|
||||
|
||||
/* XXX workaround for 3.1, not all utils zero dst before sending */
|
||||
dst->data = 0;
|
||||
|
||||
@ -193,6 +193,7 @@ extern const char * SECU_Strerror(PRErrorCode errNum);
|
||||
|
||||
/* Read the contents of a file into a SECItem */
|
||||
extern SECStatus SECU_FileToItem(SECItem *dst, PRFileDesc *src);
|
||||
extern SECStatus SECU_TextFileToItem(SECItem *dst, PRFileDesc *src);
|
||||
|
||||
/* Read in a DER from a file, may be ascii */
|
||||
extern SECStatus
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user