bugGNU Octave - Bugs: bug #47320, new function devnull

 
 

bug #47320: new function devnull

Submitter:  Carnë Draug <carandraug>
Submitted:  Wed 02 Mar 2016 02:06:46 PM UTC
   
 
Category:  Octave Function Severity:  1 - Wish
Priority:  5 - Normal Item Group:  Feature Request
Status:  None Assigned to:  carandraug
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 25 Mar 2016 03:56:12 AM UTC, comment #6: 

Would this be for the benefit of users or of core Octave scripts?  Rik's observations seem mainly relevant if the goal is to reduce the code size of Octave itself.

Python is used for many systems tasks, and so it is natural that it would need this more often than Octave does.  I can't think of any applications for which Octave is a natural choice that would use this.

However perhaps it could be part of a system-specific structure variable, with all sorts of OS/machine/compilation-specific variables, like file-separator, case-sensitivity of file names, endian-ness, 64-bit indexing etc.

Is there already a structure like that?  How can a .m file find out that information?

Lachlan Andrew <lachlan>
Wed 02 Mar 2016 06:50:44 PM UTC, comment #5: 

Yes, "NUL" is the "/dev/null" equivalent for Windows.

The question for me is whether it would be used frequently enough to justify its existence.  In the core scripts, "NUL" is only used twice in print.m which doesn't seem sufficient.


if (dos_shell)
  ## FIXME: Is this the right thing to do for DOS?
  cmd = sprintf ("%s -L %s 2> NUL", opts.fig2dev_binary, devopt);
else
  cmd = sprintf ("%s -L %s 2> /dev/null", opts.fig2dev_binary, devopt);
endif


In libinterp, it is used only three times in the dldfcn directory for _delaunayn_.cc, _voronoi_.cc, convhulln.cc.  In C++ you would probably still use ifdefs rather than an external function to get this information. 


  // Replace the outfile pointer with stdout for debugging information.
#if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)
  FILE *outfile = gnulib::fopen ("NUL", "w");
#else
  FILE *outfile = gnulib::fopen ("/dev/null", "w");
#endif



Rik <rik5>
Group administrator
Wed 02 Mar 2016 05:40:32 PM UTC, comment #4: 

I'm assuming so.  I don't know Windows but when reading on the internet, it found things like "cmd 2> NUL" being recommended for Windows.

Carnë Draug <carandraug>
Group Member
Wed 02 Mar 2016 05:25:44 PM UTC, comment #3: 

Does writing to or reading from "NUL" as a file in the mxe-octave build do what I'm assuming it should?

If so I'd say this is a good idea.

Mike Miller <mtmiller>
Group Member
Wed 02 Mar 2016 04:48:03 PM UTC, comment #2: 

Yes, it would be pretty much the same amount of lines in C++. But is it ok to add yet another function that does this?

Carnë Draug <carandraug>
Group Member
Wed 02 Mar 2016 03:00:56 PM UTC, comment #1: 

It seems like it could be a simple .m file:


function fname = devnull ()
  if (ispc ())
    fname = "NUL";
  else
    fname = "/dev/null";
  endif
endfunction


John W. Eaton <jwe>
Group administrator
Wed 02 Mar 2016 02:06:46 PM UTC, original submission:  

Python has os.devnull which:

> The file path of the null device. For example: '/dev/null' for POSIX, 'nul' for Windows.


We could have devnull() in Octave too. I would place this in libinterp/corefcn/file-io.cc next to stdout, stdin, and stderr.  But those return file handles since they are already open.  For devnull that's not necessarily true. Any opinions?

I looked into libgnu and they do:


#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
  if (strcmp (filename, "/dev/null") == 0)
    filename = "NUL";
#endif


Carnë Draug <carandraug>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by lachlan (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by carandraug (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code