delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/06/06/20:31:12

Xref: news-dnh.mv.net comp.os.msdos.djgpp:180
Path: news-dnh.mv.net!mv!news.sprintlink.net!uunet!in1.uu.net!sunic!sunic.sunet.se!news.uni-c.dk!diku.dk!terra
From: terra AT diku DOT dk (Morten Welinder)
Newsgroups: comp.os.msdos.djgpp
Subject: Code Standards
Date: 6 Jun 1995 20:31:04 GMT
Organization: Department of Computer Science, U of Copenhagen
Lines: 109
Sender: terra AT tyr DOT diku DOT dk
Nntp-Posting-Host: odin.diku.dk
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Dj-Gateway: from newsgroup comp.os.msdos.djgpp

OK, some thoughts of mine.



GO32:
----

Go32 is dead.  The majority of comments yours truthfully put
in there when I got tired of just seeing "case 0x40:".  If this
program was not dead it would IMHO need more commenting.

Having said that I want to add that there really are no or few
user-servicable parts inside.  If you don't have your i[345]86-
manual within reach (and know it almost be heart) don't mess
with it.


CWSDPMI:
-------

Better, but nor perfect.  Still, this is expert-only code.



LIBC:
----

Most of the routines are short.  Look at the current (for a few
more days) version of rename.c below.  What more comments do
you want?  (Forget about those in the docs and those that are
relevant to the entire libc, like what the heck is __tb?)


Morten
------

No comments needed here.



---------------------------------------------------------------------------

#include <libc/stubs.h>
#include <stdio.h>
#include <errno.h>
#include <dpmi.h>
#include <go32.h>

#include <libc/dosio.h>

int
rename(const char *old, const char *new)
{
  __dpmi_regs r;
  int olen    = strlen(old) + 1;
  int i;

  for (i=0; i<2; i++)
  {
    r.h.ah = 0x56;
    _put_path2(new, olen);
    _put_path(old);
    __dpmi_int(0x21, &r);
    if(r.x.flags & 1)
    {
      if (r.h.ah == 5 && i == 0) /* access denied */
	remove(new);		 /* and try again */
      else
      {
	errno = __doserr_to_errno(r.x.ax);
	return -1;
      }
    }
    else
      break;
  }
  return 0;
}


---------------------------------------------------------------------------

@node rename, file system
@unnumberedsec @code{rename}
@subheading Syntax

@example
#include <stdio.h>

int rename(const char *oldname, const char *newname);
@end example

@subheading Description

This function renames an existing file @var{oldname} to @var{newname}. 
Wildcards are not allowed, but the two file names may reflect different
subdirectories on the same file system.

@subheading Return Value

Zero on success, nonzero on failure.

@subheading Example

@example
rename("some.doc", "some.sav");
@end example

---------------------------------------------------------------------------

- Raw text -


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