Skip to content

Commit

Permalink
Is. #681 - read-only files, and dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffmcl committed Feb 21, 2021
1 parent 9f8d957 commit 91e8347
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/tidylib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,19 +1125,26 @@ int TIDY_CALL tidyParseSource( TidyDoc tdoc, TidyInputSource* source )
return tidyDocParseSource( doc, source );
}


#ifdef WIN32
#define M_IS_DIR _S_IFDIR
#else // !WIN32
#define M_IS_DIR S_IFDIR
#endif
int tidyDocParseFile( TidyDocImpl* doc, ctmbstr filnam )
{
int status = -ENOENT;
FILE* fin = fopen( filnam, "r+" );

if ( !fin )
FILE* fin = 0;
struct stat sbuf = { 0 }; /* Is. #681 - read-only files */
if ( stat(filnam,&sbuf) != 0 )
{
TY_(ReportFileError)( doc, filnam, FILE_NOT_FILE );
return status;
}

fclose( fin );
if (sbuf.st_mode & M_IS_DIR) /* and /NOT/ if a DIRECTORY */
{
TY_(ReportFileError)(doc, filnam, FILE_NOT_FILE);
return status;
}

#ifdef _WIN32
return TY_(DocParseFileWithMappedFile)( doc, filnam );
Expand All @@ -1147,7 +1154,6 @@ int tidyDocParseFile( TidyDocImpl* doc, ctmbstr filnam )

#if PRESERVE_FILE_TIMES
{
struct stat sbuf = { 0 };
/* get last modified time */
TidyClearMemory(&doc->filetimes, sizeof(doc->filetimes));
if (fin && cfgBool(doc, TidyKeepFileTimes) &&
Expand Down

0 comments on commit 91e8347

Please sign in to comment.