Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7442735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:13:17+00:00 2026-05-29T11:13:17+00:00

I am beginning to design a shell application to run within a Linux terminal

  • 0

I am beginning to design a shell application to run within a Linux terminal for a class I am taking.

This, of course, will involve reading variable-length input strings (commands) from the user. I know that I can simply read each command into a buffer of a size that I would consider appropriate, but this has the potential to either a) truncate the command or b) cause a buffer overflow.

If possible, how can way limit the length of user input to the console?

Say, if I set the command length to 3, 123 would be allowed, but if 123 were already present in the input string (before the user has pressed enter) and the user attempted to add 4, no character would print to the console, perhaps even with an ‘error ping’.

I realize that I could design such functionality, but if that is needed, I am not sure where to start to do such a thing.

Either a pre-existing solution or advice on implementing my own solution would be greatly appreciated.

Edit:

I suppose a cheap and easy solution would be to read a command on character at a time until an enter signal is reached or the maximum length is reached. Would problems arise with a solution of this sort?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:13:18+00:00Added an answer on May 29, 2026 at 11:13 am

    I have little experience with readline, but here’s what you could try:

    • Write a function that checks rl_end (the number of characters in rl_line_buffer)
      • If you want to allow more, just return rl_getc
      • If not, you can use rl_ding
    • Set the rl_getc_function to call your function as described above

    As a side note, if you do use readline, you don’t need to limit the input at all (the library manages its memory as it goes). Another (simpler) function you might be interested in is getline.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm beginning the design of a medium-sized web application. I usually like to design
I'm beginning to design a web-based API and the very first issue—how will users
I'm beginning to design the infrastructure of web application developed with ASP.NET MVC preview
I am just beginning design work on a problem that I'm sure has been
Many beginning programmers write code like this: sub copy_file ($$) { my $from =
I am beginning to design a new laboratory test data management system with many
I am just beginning to build my Rails application and thus far I've followed
I've been struggling with an application I'm writing and I think I'm beginning to
We're beginning to design a new product, and our UI guy is knocking out
I am beginning to adopt Test Driven Design (TDD) behaviors and workflow for my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.