delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/10/16/00:14:15

From: sandmann AT clio DOT rice DOT edu (Charles Sandmann)
Message-Id: <10110160409.AA14685@clio.rice.edu>
Subject: Re: W2K/XP fncase [code]
To: eliz AT is DOT elta DOT co DOT il
Date: Mon, 15 Oct 2001 23:09:23 -0500 (CDT)
Cc: djgpp-workers AT delorie DOT com
In-Reply-To: <8361-Mon15Oct2001232127+0200-eliz@is.elta.co.il> from "Eli Zaretskii" at Oct 15, 2001 11:21:28 PM
X-Mailer: ELM [version 2.5 PL2]
Mime-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Comments?  If these are OK I'll also:
Add entry to makefile
Add prototype in fcntl.h
Add entry in wc204
Then look at potentially using it (I want to visually inspect the 7 
potential uses for possible other test cases before commit anyway).

*** _use_lfn.BAK	Tue Aug  7 02:55:26 2001
--- _use_lfn.txh	Mon Oct 15 22:22:34 2001
*************** and returns that.  It will do the same i
*** 213,216 ****
--- 213,220 ----
  characters illegal in a filename.
  
+ This function returns incorrect results on Windows 2000 and Windows XP
+ due to bugs in the implementation of the DPMI call on those platforms.
+ Do not use this function in those environments.
+ 
  You might need to call this function if you want to know whether a given
  filename is valid on MSDOS: if a case-sensitive string comparison
*************** If the underlying system calls fail, the
*** 333,334 ****
--- 337,378 ----
   unsigned file_stamp = _lfn_get_ftime (handle, _LFN_CTIME);
  @end example
+ 
+ @c -----------------------------------------------------------------------
+ 
+ @node _is_DOS83, file system
+ @subheading Syntax
+  
+ @example
+ #include <fcntl.h>
+ 
+ int _is_DOS83 (const char *fname);
+ @end example
+ 
+ @subheading Description
+ 
+ This function checks the filename pointed to by @var{fname} to 
+ determine if it is a standard short (8+3) form file name.  The 
+ filename should only include the name part of the file.  It is
+ expected the filename will contain a valid long or short file
+ name (no validation is done to exclude path characters or 
+ characters always illegal in any file name).
+ 
+ The function will return 0 (failure) if there are more than 8 
+ characters before a period, more than 3 characters after a period, 
+ more than one period, starts with a period, any lower case characters, 
+ or any of the special characters @kbd{+,;=[]} or a space.  The 
+ special names . and .. are exceptions and will return sucess.
+ 
+ This function could be called to determine if a filename is valid on 
+ DOS before long file name support.  If this function returns 1 the 
+ filename probably does not have a long name entry on a FAT file 
+ system.  The library internally calls this function to determine
+ if a file should have it's name lower cased when fncase=n.
+ 
+ @subheading Return value
+ 
+ The function returns an integer 0 (not DOS 8.3) or 1 (DOS 8.3)
+ 
+ @subheading Portability
+ 
+ @portability !ansi, !posix

------is_dos83.c---------------------------------------------------------
/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
#include <fcntl.h>

int _is_DOS83(const char *fname)
{
  const char *s = fname;
  const char *e;
  char c, period_seen;

  if (*s == '.') {
    if (s[1] == 0)
      return 1;				/* "." is valid */
    if (s[1] == '.' && s[2] == 0)
      return 1;				/* ".." is valid */
    return 0;				/* starting period invalid */
  }

  period_seen = 0;
  e = s + 8;				/* end */

  while ((c = *s++))
    if (c == '.') {
      if(period_seen)
        return 0;			/* multiple periods invalid */
      period_seen = 1;
      e = s + 3;			/* already one past period */
    } else if (s > e)
      return 0;				/* name component too long */
    else if (c >= 'a' && c <= 'z')
      return 0;				/* lower case character */
    else if (c == '+' || c == ',' || c == ';' || c == ' ' ||
             c == '=' || c == '[' || c == ']')
      return 0;				/* special non-DOS characters */

  return 1;				/* all chars OK */
}

#ifdef TEST
#include <stdio.h>
#include <crt0.h>

int _crt0_startup_flags = _CRT0_FLAG_PRESERVE_FILENAME_CASE; /* for glob */

#define MAXDISPLAY 10

/* Example test usage: id83 * (or a file name, or ... can test whole disk) */

int main (int argc, char *argv[])
{
  char old, new, dif;
  char sh[14];
  char *f;
  int i,j,nd;
  nd = 0;
  for(i=1;i<argc;i++) {
    f = argv[i];
    for(j=strlen(f); j >= 0; j--)	/* Trim path */
      if(*(f+j) == '/') {
        f = f + j + 1;
        break;
      }
    old = !strcmp(_lfn_gen_short_fname(f, sh), f);
    new = _is_DOS83(f);
    dif = (old != new);
    if(dif)
      nd++;
    if(i == MAXDISPLAY)
      printf("Remaining test results suppressed unless different\n");
    if(dif || i < MAXDISPLAY)
      printf ("isDOS: %d old: %d Name: %s\n", new, old, f);
  }
  if(i >= MAXDISPLAY)
    printf("%d names processed, %d differences\n",i,nd);
  return 0;
}
#endif

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019