X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdata-io%2Ffile-handle.q;h=d53017735259eeec6b6cb2635fa4dd5734e9f17e;hb=6435b289a7c00df2445a491490869d7d1f2bc3bc;hp=f1c7cb54afd868875c921b4f7769b9305a37ec67;hpb=43b1296aafe7582e7dbe6c2b6a8b478d7d9b0fcf;p=pspp diff --git a/src/language/data-io/file-handle.q b/src/language/data-io/file-handle.q index f1c7cb54af..d530177352 100644 --- a/src/language/data-io/file-handle.q +++ b/src/language/data-io/file-handle.q @@ -19,17 +19,17 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include +#include "xalloc.h" + #include "gettext.h" #define _(msgid) gettext (msgid) @@ -93,15 +93,15 @@ cmd_file_handle (struct lexer *lexer, struct dataset *ds) break; case FH_IMAGE: properties.mode = FH_MODE_BINARY; - if (cmd.n_lrecl[0] == NOT_LONG) + if (cmd.n_lrecl[0] == LONG_MIN) msg (SE, _("Fixed-length records were specified on /RECFORM, but " "record length was not specified on /LRECL. " - "Assuming %u-character records."), - (unsigned int) properties.record_width); + "Assuming %zu-character records."), + properties.record_width); else if (cmd.n_lrecl[0] < 1) msg (SE, _("Record length (%ld) must be at least one byte. " - "Assuming %u-character records."), - cmd.n_lrecl[0], (unsigned int) properties.record_width); + "Assuming %zu-character records."), + cmd.n_lrecl[0], properties.record_width); else properties.record_width = cmd.n_lrecl[0]; break; @@ -133,8 +133,7 @@ cmd_close_file_handle (struct lexer *lexer, struct dataset *ds UNUSED) if (handle == NULL) return CMD_CASCADING_FAILURE; - fh_free (handle); - + fh_unname (handle); return CMD_SUCCESS; } @@ -158,7 +157,10 @@ referent_name (enum fh_referent referent) /* Parses a file handle name, which may be a file name as a string or a file handle name as an identifier. The allowed types of file handle are restricted to those in REFERENT_MASK. Returns - the file handle when successful, a null pointer on failure. */ + the file handle when successful, a null pointer on failure. + + The caller is responsible for fh_unref()'ing the returned + file handle when it is no longer needed. */ struct file_handle * fh_parse (struct lexer *lexer, enum fh_referent referent_mask) { @@ -177,8 +179,6 @@ fh_parse (struct lexer *lexer, enum fh_referent referent_mask) handle = NULL; if (lex_token (lexer) == T_ID) handle = fh_from_id (lex_tokid (lexer)); - if (handle == NULL) - handle = fh_from_file_name (ds_cstr (lex_tokstr (lexer))); if (handle == NULL) { if (lex_token (lexer) != T_ID || lex_tokid (lexer)[0] != '#' || get_syntax () != ENHANCED) @@ -194,6 +194,7 @@ fh_parse (struct lexer *lexer, enum fh_referent referent_mask) { msg (SE, _("Handle for %s not allowed here."), referent_name (fh_get_referent (handle))); + fh_unref (handle); return NULL; }