/* Copyright (c) 1979 Regents of the University of California */
static char sccsid
[] = "@(#)GETNAME.c 1.1 %G%";
* GETNAME - activate a file
* takes a name, name length, element size, and variable
* level and returns a pointer to a file structure.
* a new file structure is initialized if necessary.
* temporary names are generated, and given
* names are blank trimmed.
GETNAME(filep
, name
, maxnamlen
, datasize
)
register struct iorec
*filep
;
if (filep
->fblk
>= MAXFILES
|| _actfile
[filep
->fblk
] != filep
) {
* initialize a new filerecord
filep
->llimit
= 0x7fffffff;
filep
->fileptr
= &filep
->window
[0];
* check to see if file is global, or allocated in
* the stack by checking its address against the
* address of one of our routine's local variables.
if (++_filefre
== MAXFILES
)
} while (_actfile
[_filefre
] != FILNIL
);
_actfile
[_filefre
] = filep
;
* link the newrecord into the file chain
prev
= (struct iorec
*)&_fchain
;
while (filep
->flev
> next
->flev
) {
if (filep
->funit
& FDEF
) {
filep
->funit
&= (TEMP
| FTEXT
);
* have a previous buffer, close associated file
if (ferror(filep
->fbuf
)) {
ERROR(ECLOSE
, filep
->pfname
);
* renamed temporary files are discarded
if ((filep
->funit
& TEMP
) &&
(unlink(filep
->pfname
))) {
ERROR(EREMOVE
, filep
->pfname
);
filep
->funit
&= (TEMP
| FTEXT
);
* get the filename associated with the buffer
if (*filep
->fname
!= NULL
) {
* no name given and no previous name, so generate
* a new one of the form tmp.xxxxxx
name
= mktemp("tmp.XXXXXX");
* trim trailing blanks, and insure that the name
* will fit into the file structure
for (cnt
= 0; cnt
< maxnamlen
; cnt
++)
if (name
[cnt
] == '\0' || name
[cnt
] == ' ')
* put the new name into the structure
for (cnt
= 0; cnt
< maxnamlen
; cnt
++)
filep
->fname
[cnt
] = name
[cnt
];
filep
->fname
[cnt
] = '\0';
filep
->pfname
= &filep
->fname
[0];