WIP: libc.obj: implement gets_s
#438
Draft
Egor00f
wants to merge 4 commits from
Egor00f/kolibrios:add-`gets_s` into main
pull from: Egor00f/kolibrios:add-`gets_s`
merge into: KolibriOS:main
KolibriOS:main
KolibriOS:wolf3d-launcher
KolibriOS:icons-update
KolibriOS:kterm-upload
KolibriOS:app/socketdbg_fix1
KolibriOS:hdaudio-add-ring-buffer-for-unsolicied-events
KolibriOS:workflow-fuse
KolibriOS:add-license-file-header-to-guide
KolibriOS:blocks-add-models
KolibriOS:shell-improve-cpuid
KolibriOS:rewrite_ide_drv
KolibriOS:qrcodegen
KolibriOS:ci/update
KolibriOS:laser-tank-fix-win-height
KolibriOS:improvement/commit-and-branch-styles
KolibriOS:docs/libs
Labels
Clear labels
C
Category/Applications
Category/Drivers
Category/General
Category/Kernel
Category/Libraries
Eolite
FASM
FS
GSoC
HardwareTested
HLL
Influence/Settings
Influence/Text/TYPO
IRCC
Kernel
Pay for the code
This issue in GSoC program
Kind
Breaking
Breaking change that won't be backward compatible
Kind
Bug
Something is not working
Kind
Build
Kind
Documentation
Documentation changes
Kind
Enhancement
Improve existing functionality
Kind
Feature
New functionality
Kind
Security
This is security issue
Kind
Testing
Issue or pull request related to testing
Paid task
PR
Conflicts
PR conflicts with main
PR
Dependent
This PR is dependent on another PR
Priority
Critical
The priority is critical
Priority
High
The priority is high
Priority
Low
The priority is low
Priority
Medium
The priority is medium
PR
Ready to merge
Pull request is ready for merge
PR
Request changes
Changes requested in pull request
PR
Review required
Reviewed
Confirmed
Issue has been confirmed
Reviewed
Duplicate
This issue or pull request already exists
Reviewed
Invalid
Invalid issue
Reviewed
Won't Fix
This issue won't be fixed
Status
Abandoned
Somebody has started to work on this but abandoned work
Status
Blocked
Something is blocking this issue or pull request
Status
Need More Info
Feedback is required to reproduce issue or to continue work
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: KolibriOS/kolibrios#438
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "Egor00f/kolibrios:add-`gets_s`"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Changes
new functions:
gets_sgetsis defined asand
getsDIDN'T BECOME SAFEa80783a903tod7adcd1caad7adcd1caatoc3d1506c18c3d1506c18tof814987094Problems I see:
🟥
stdio.h'sgetsmacro referencesSTDIO_MAX_MEM.Fixed:
stdio.hnow#include <limits.h>, soSTDIO_MAX_MEMis available wherever<stdio.h>is; the plain#include <stdio.h>; gets(buf);case compiles again.🟥 C89/C99 conformance & portability — only the ABI half is fixed.
ABI part fixed:
getsis exported again (libc.defkeepsgets+gets_s;EXPORTS[] = { "gets", &_gets }), so pre-built binaries link.Still broken at C-source level:
stdio.hhas only#define gets(str) gets_s(...)and no realchar *gets(char*)declaration (the function is the internal_gets, which user code can't portably name). The standard (C89 §4.1.6 / C99 §7.1.4) requires the actual function to stay reachable when masked by a macro. So&gets,(gets)(buf),#undef gets; gets(...), andextern char *gets(char*);redeclarations still fail to compile. This still hurts porting C89/C99 software to KolibriOS — the original concern.Fix: declare a real prototype in
stdio.h—DLLAPI char* gets(char* str);— and name the functiongets(drop the_getsindirection); keep the macro alongside if safe-by-default is wanted. The_getswrapper is exactly what keeps the source-level breakage.🟨 ABI note — resolved:
getssymbol kept (via&_gets), pre-built binaries no longer break.🟨 The
getscompat macro preserves the old unsafe behavior.gets(buf)→gets_s(buf, STDIO_MAX_MEM=4096)regardless of the real buffer size — no added safety for existing callers; benefit exists only when code explicitly callsgets_s(buf, sizeof buf). Acceptable as a migration shim, but state it so it isn't mistaken for a fix of existing call sites.🟨 Not full C11 Annex K
gets_s.Improved (now clears
str[0]onEINVAL/EIO), but still no constraint handler. Acceptable for a minimal libc — it's "gets_s-like"; note it in the PR description.🟨
gets.cdropped its own#include <limits.h>while still usingINT_MAX.n > (size_t)INT_MAXnow relies onINT_MAXarriving transitively viastdio.h → limits.h. Include-what-you-use regression — re-add#include <limits.h>togets.c; it depends on it directly.🟨 New sample
gets_s_test.cis not wired into the build.Unlike
abort_test/atexit_testin PR 340, it isn't added toMakefile/build_all.sh, so it won't be auto-built/tested. Also trailing whitespace onreturn 0;.See comment above.
Egor00f referenced this pull request2026-05-19 17:01:50 +00:00
gets_see6df29e4dgetsas function && updategets_s&& includelimits.hinstdio.h&& addgets_stest810204d56fto035ed0790bView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.