Logo Search packages:      
Sourcecode: cbmconvert version File versions  Download package

enum WrStatus WriteNative ( const struct Filename name,
const byte_t data,
size_t  length,
char **  newname,
log_t  log 

Write a file in raw format

name native (PETSCII) name of the file
data the contents of the file
length length of the file contents
newname (output) the converted file name
log Call-back function for diagnostic output
status of the operation

Definition at line 251 of file write.c.

References do_it(), Errors, filename2char(), filesuffix(), and WrFail.

  struct stat statbuf;
  char* filename;
  int i;

  if (!filename2char (name, newname))
    return WrFail;

  if (!(filename = malloc (strlen (*newname) + (4 + 5 + 1)))) {
    free (filename);
    return WrFail;

  /* try the plain filename */
  sprintf (filename, "%s%.4s", *newname, filesuffix (name));

  if (stat (filename, &statbuf)) {
    free (*newname);
    *newname = filename;
    return do_it (data, length, newname, name, log);

  for (i = 0; i < 10000; i++) {
    sprintf (filename, "%s~%d%.4s", *newname, i, filesuffix (name));
    if (stat (filename, &statbuf)) { /* found an available file name */
      free (*newname);
      *newname = filename;
      return do_it (data, length, newname, name, log);

  (*log) (Errors, name, "out of file name space");
  return WrFail;

Generated by  Doxygen 1.6.0   Back to index