ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.