LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-17-2014, 08:08 AM   #31
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930

Quote:
Originally Posted by Spect73 View Post
Of course you are correct. Since none of this helps the OP, we should quit.
Quite right, I believe I said at one point that it boils down to style and however protective you wish to write your code. But I do think the OP was exploring the language. Yep, they're probably in overload on the subject, but at least they have some excellent points. I personally would use a "per character" parser, and therefore only have acceptable exits designed to be the correct answers, or an escape condition; such as SIGINT.

I do understand that the definition of your input buffer is defined in the kernel build. I didn't dig deeply into Spect73's posting, except to compile and run that code and change the definition from 1024 to other values to assure myself that the result of 1024 wasn't conveniently due to that #define. Still, isn't 1024 potentially too small? For instance that affects things when you run make and gcc and if you have a very lengthy path; along with a number of arguments to your line, you may hit 1024. I have an embedded system where the serial buffer max values are 4096, because I was using 65535 as my PIPE size and then realized by code inspection that receives from serial USB could never exceed 4096. It makes me curious to look at the kernel and see the prevailing definition for the stdin size. Where I ended was limits.h:

Code:
#ifndef _LINUX_LIMITS_H
#define _LINUX_LIMITS_H

#define NR_OPEN	        1024

#define NGROUPS_MAX    65536	/* supplemental group IDs are available */
#define ARG_MAX       131072	/* # bytes of args + environ for exec() */
#define LINK_MAX         127	/* # links a file may have */
#define MAX_CANON        255	/* size of the canonical input queue */
#define MAX_INPUT        255	/* size of the type-ahead buffer */
#define NAME_MAX         255	/* # chars in a file name */
#define PATH_MAX        4096	/* # chars in a path name including nul */
#define PIPE_BUF        4096	/* # bytes in atomic write to a pipe */
#define XATTR_NAME_MAX   255	/* # chars in an extended attribute name */
#define XATTR_SIZE_MAX 65536	/* size of an extended attribute value (64k) */
#define XATTR_LIST_MAX 65536	/* size of extended attribute namelist (64k) */

#define RTSIG_MAX	  32

#endif
Not sure if that means that the max would then be 4096, PIPE_BUF.
 
Old 01-17-2014, 12:25 PM   #32
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
SIGINT would have to be handled completely differently, since it is a signal. It is way outside of the topic of this thread and in most simple applications one doesn't have to worry about it at all.

Quote:
Originally Posted by rtmistler
I do understand that the definition of your input buffer is defined in the kernel build.
It isn't. What the C library uses is dependent on the library, and standard does not impose any limits.

Quote:
Originally Posted by rtmistler
I didn't dig deeply into Spect73's posting, except to compile and run that code and change the definition from 1024 to other values to assure myself that the result of 1024 wasn't conveniently due to that #define. Still, isn't 1024 potentially too small?
I'm sorry, but I have no idea what you're talking about. Too small for what? To hold a line? It might, since there are no limits to the length of a single line read from standard input.

Quote:
Originally Posted by rtmistler
Not sure if that means that the max would then be 4096, PIPE_BUF.
PIPE_BUF is what it says in the comment – maximum number of bytes you can write to a pipe in an atomic way. I.e. such that the reader will be able to receive that data using a single read call. It has nothing to do with the length of a line on standard input.
 
Old 01-17-2014, 12:59 PM   #33
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by mina86 View Post
I'm sorry, but I have no idea what you're talking about. Too small for what? To hold a line? It might, since there are no limits to the length of a single line read from standard input.
Yes, I meant too small for a line. Years ago I think the command line would accept say 256 characters and people would create makes based on a local directory. Eventually you'd run into a problem, for instance if the original author used a short path like /home/mylogin and that was it, things worked fine. But if you copied and used a root path like /home/temporary-login/releases-of-that-demo/january-17-2014-version/first-pass and when the Make ran it would include that path in most of the gcc lines, there would be problems. One had to alter their command line capabilities to allow for more than what it originally allowed or not use so extensive of a home directory size. Eventually that got fixed either by having a much larger number or making it unlimited by some technique other than a fixed array. I do think that 1024 may be too short for some of the Make lines which may occur. I'm not up to date on how the command parser works and therefore when you say there are no limits to the length of a single line read; then maybe there is no longer any risk of some shell command offered by a Make process which could ever exceed what a command shell could take.

Sorry for any confusion due to my lack of clarity or knowledge on some of that.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
Bash script issue (for loop inside a loop) Mperonen Programming 3 08-08-2013 02:14 AM
[SOLVED] Using while loop & select statement - Loop issues Kustom42 Programming 4 05-17-2013 08:43 AM
[SOLVED] Bash - While Loop reading from two lists simultaneously - nested while loop wolverene13 Programming 11 10-01-2011 05:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration