2016-03-31 22:33:56

by Richard Weinberger

[permalink] [raw]
Subject: New syscall: leftpad()

Recent happenings in the node.js community showed how fragile software is when
it comes to dependencies of fundamental algorithms like leftpad[1].
A node.js package which provided ledpad vanished and broke a lot of software.
This raised our attention and we came to the conclusion that it is the kernel's
job to provide such functionality such that node.js based applications can in future
rely in Linux's "don't break userspace" rule.
We hope that glibc and Andoid's bionic will soon offer wrapper functions for this
new leftpad system call.
We put leftpad into the kernel not only because of Linux's stable ABI,
also for performance reasons.
As everyone knows, within the kernel everything is faster and better.
Leftpad has millions of users, so it has to be as fast as possible.
This new system call will also help making services like left-pad.io[2]
faster and more reliable. If the leftpad() system call gets adopted by a wider user base
it might also make sense to add a generic npm() system call which acts like ioctl()
where kernel modules can register new functions that are often used by node.js.
Such functions might be, is_array(), is_int(), etc.

Enjoy,
//richard

[1] http://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/
[2] http://left-pad.io/

[PATCH] Implement leftpad syscall
[PATCH] leftpad.2: Document new syscall


2016-03-31 22:33:58

by Richard Weinberger

[permalink] [raw]
Subject: [PATCH] Implement leftpad syscall

From: David Gstir <[email protected]>

Implement the leftpad() system call such that userspace,
especially node.js applications, can in the near future directly
use it and no longer depend on fragile npm packages.

Signed-off-by: David Gstir <[email protected]>
Signed-off-by: Richard Weinberger <[email protected]>
---
arch/x86/entry/syscalls/syscall_64.tbl | 1 +
include/linux/syscalls.h | 1 +
kernel/sys.c | 35 ++++++++++++++++++++++++++++++++++
kernel/sys_ni.c | 1 +
4 files changed, 38 insertions(+)

diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl
index cac6d17..f287712 100644
--- a/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/arch/x86/entry/syscalls/syscall_64.tbl
@@ -335,6 +335,7 @@
326 common copy_file_range sys_copy_file_range
327 64 preadv2 sys_preadv2
328 64 pwritev2 sys_pwritev2
+329 common leftpad sys_leftpad

#
# x32-specific system call numbers start at 512 to avoid cache impact
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index d795472..a0850bb 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -898,4 +898,5 @@ asmlinkage long sys_copy_file_range(int fd_in, loff_t __user *off_in,

asmlinkage long sys_mlock2(unsigned long start, size_t len, int flags);

+asmlinkage long sys_leftpad(char *str, char pad, char *dst, size_t dst_len);
#endif
diff --git a/kernel/sys.c b/kernel/sys.c
index cf8ba54..e42d972 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -2432,3 +2432,38 @@ COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info)
return 0;
}
#endif /* CONFIG_COMPAT */
+
+
+SYSCALL_DEFINE4(leftpad, char *, src, char, pad, char *, dst, size_t, dst_len)
+{
+ char *buf;
+ long ret;
+ size_t len = strlen_user(src);
+ size_t pad_len = dst_len - len;
+
+ if (dst_len <= len || dst_len > 4096) {
+ return -EINVAL;
+ }
+
+ buf = kmalloc(dst_len, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
+ memset(buf, pad, pad_len);
+ ret = copy_from_user(buf + pad_len, src, len);
+ if (ret) {
+ ret = -EFAULT;
+ goto out;
+ }
+
+ ret = copy_to_user(dst, buf, dst_len);
+ if (ret) {
+ ret = -EFAULT;
+ goto out;
+ }
+
+ ret = pad_len;
+out:
+ kfree(buf);
+ return ret;
+}
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index 2c5e3a8..262608d 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -175,6 +175,7 @@ cond_syscall(sys_setfsgid);
cond_syscall(sys_capget);
cond_syscall(sys_capset);
cond_syscall(sys_copy_file_range);
+cond_syscall(sys_leftpad);

/* arch-specific weak syscall entries */
cond_syscall(sys_pciconfig_read);
--
1.8.4.5

2016-03-31 22:34:18

by Richard Weinberger

[permalink] [raw]
Subject: [PATCH] leftpad.2: Document new syscall

From: Daniel Walter <[email protected]>

Signed-off-by: Daniel Walter <[email protected]>
Signed-off-by: Richard Weinberger <[email protected]>
---
man2/leftpad.2 | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644 man2/leftpad.2

diff --git a/man2/leftpad.2 b/man2/leftpad.2
new file mode 100644
index 0000000..ff5f401
--- /dev/null
+++ b/man2/leftpad.2
@@ -0,0 +1,55 @@
+.\" Copyright (c) 2016 sigma-star gmbh
+.\" ([email protected])
+.\"
+.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
+.\" This is free documentation; you can redistribute it and/or
+.\" modify it under the terms of the GNU General Public License as
+.\" published by the Free Software Foundation; either version 2 of
+.\" the License, or (at your option) any later version.
+.\"
+.\" The GNU General Public License's references to "object code"
+.\" and "executables" are to be interpreted as the output of any
+.\" document formatting or typesetting system, including
+.\" intermediate and printed output.
+.\"
+.\" This manual is distributed in the hope that it will be useful,
+.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
+.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+.\" GNU General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public
+.\" License along with this manual; if not, see
+.\" <http://www.gnu.org/licenses/>.
+.\" %%%LICENSE_END
+.\"
+.TH LEFTPAD 2 2016-04-01 "Linux" "Linux Programmer's Manual"
+.SH NAME
+leftpad
+.SH SYNOPSIS
+.nf
+.B #include <sys/types.h>
+
+.BI "int leftpad(char *src, char pad, char *dst, size_t dst_len);
+.fi
+.SH DESCRIPTION
+This function provides left padding for strings.
+.LP
+The string in
+.I src
+will be left padded with the chosen padding character
+.I pad
+and stored in
+.I dst
+ .
+.SH RETURN VALUE
+On success, returns the number of padding characters added.
+.SH ERRORS
+.TP
+.B EINVAL
+The size of the destination buffer
+.I dst
+is shorter than the source string
+.I src
+ . Or the destination string is longer than 4096 bytes.
+.SH SEE ALSO
+.BR snprintf (3)
--
2.7.3

Subject: Re: [PATCH] Implement leftpad syscall

On 04/01/2016 11:33 AM, Richard Weinberger wrote:
> From: David Gstir <[email protected]>
>
> Implement the leftpad() system call such that userspace,
> especially node.js applications, can in the near future directly
> use it and no longer depend on fragile npm packages.

Works can't express the importance of adding this system call!
Thanks so much for proposing and implementing it!

Acked-by: Michael Kerrisk <[email protected]>

Cheers,

Michael

> Signed-off-by: David Gstir <[email protected]>
> Signed-off-by: Richard Weinberger <[email protected]>
> ---
> arch/x86/entry/syscalls/syscall_64.tbl | 1 +
> include/linux/syscalls.h | 1 +
> kernel/sys.c | 35 ++++++++++++++++++++++++++++++++++
> kernel/sys_ni.c | 1 +
> 4 files changed, 38 insertions(+)
>
> diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl
> index cac6d17..f287712 100644
> --- a/arch/x86/entry/syscalls/syscall_64.tbl
> +++ b/arch/x86/entry/syscalls/syscall_64.tbl
> @@ -335,6 +335,7 @@
> 326 common copy_file_range sys_copy_file_range
> 327 64 preadv2 sys_preadv2
> 328 64 pwritev2 sys_pwritev2
> +329 common leftpad sys_leftpad
>
> #
> # x32-specific system call numbers start at 512 to avoid cache impact
> diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
> index d795472..a0850bb 100644
> --- a/include/linux/syscalls.h
> +++ b/include/linux/syscalls.h
> @@ -898,4 +898,5 @@ asmlinkage long sys_copy_file_range(int fd_in, loff_t __user *off_in,
>
> asmlinkage long sys_mlock2(unsigned long start, size_t len, int flags);
>
> +asmlinkage long sys_leftpad(char *str, char pad, char *dst, size_t dst_len);
> #endif
> diff --git a/kernel/sys.c b/kernel/sys.c
> index cf8ba54..e42d972 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -2432,3 +2432,38 @@ COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info)
> return 0;
> }
> #endif /* CONFIG_COMPAT */
> +
> +
> +SYSCALL_DEFINE4(leftpad, char *, src, char, pad, char *, dst, size_t, dst_len)
> +{
> + char *buf;
> + long ret;
> + size_t len = strlen_user(src);
> + size_t pad_len = dst_len - len;
> +
> + if (dst_len <= len || dst_len > 4096) {
> + return -EINVAL;
> + }
> +
> + buf = kmalloc(dst_len, GFP_KERNEL);
> + if (!buf)
> + return -ENOMEM;
> +
> + memset(buf, pad, pad_len);
> + ret = copy_from_user(buf + pad_len, src, len);
> + if (ret) {
> + ret = -EFAULT;
> + goto out;
> + }
> +
> + ret = copy_to_user(dst, buf, dst_len);
> + if (ret) {
> + ret = -EFAULT;
> + goto out;
> + }
> +
> + ret = pad_len;
> +out:
> + kfree(buf);
> + return ret;
> +}
> diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
> index 2c5e3a8..262608d 100644
> --- a/kernel/sys_ni.c
> +++ b/kernel/sys_ni.c
> @@ -175,6 +175,7 @@ cond_syscall(sys_setfsgid);
> cond_syscall(sys_capget);
> cond_syscall(sys_capset);
> cond_syscall(sys_copy_file_range);
> +cond_syscall(sys_leftpad);
>
> /* arch-specific weak syscall entries */
> cond_syscall(sys_pciconfig_read);
>


--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

2016-03-31 23:09:34

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] Implement leftpad syscall

On Fri, Apr 01, 2016 at 12:33:32AM +0200, Richard Weinberger wrote:
> + if (dst_len <= len || dst_len > 4096) {
> + return -EINVAL;
> + }

Please always use checkpatch.pl when submitting patches.

thanks,

greg k-h

2016-03-31 23:36:31

by Randy Dunlap

[permalink] [raw]
Subject: Re: New syscall: leftpad()

Please be more careful in your description...

On 03/31/16 15:33, Richard Weinberger wrote:
> Recent happenings in the node.js community showed how fragile software is when
> it comes to dependencies of fundamental algorithms like leftpad[1].
> A node.js package which provided ledpad vanished and broke a lot of software.

leftpad

> This raised our attention and we came to the conclusion that it is the kernel's
> job to provide such functionality such that node.js based applications can in future
> rely in Linux's "don't break userspace" rule.
> We hope that glibc and Andoid's bionic will soon offer wrapper functions for this

Android's

> new leftpad system call.
> We put leftpad into the kernel not only because of Linux's stable ABI,
> also for performance reasons.
> As everyone knows, within the kernel everything is faster and better.
> Leftpad has millions of users, so it has to be as fast as possible.
> This new system call will also help making services like left-pad.io[2]
> faster and more reliable. If the leftpad() system call gets adopted by a wider user base
> it might also make sense to add a generic npm() system call which acts like ioctl()
> where kernel modules can register new functions that are often used by node.js.
> Such functions might be, is_array(), is_int(), etc.


--
~Randy

2016-04-01 01:33:40

by Frederic Weisbecker

[permalink] [raw]
Subject: Re: [PATCH] Implement leftpad syscall

On Fri, Apr 01, 2016 at 12:33:32AM +0200, Richard Weinberger wrote:
> From: David Gstir <[email protected]>
>
> Implement the leftpad() system call such that userspace,
> especially node.js applications, can in the near future directly
> use it and no longer depend on fragile npm packages.
>
> Signed-off-by: David Gstir <[email protected]>
> Signed-off-by: Richard Weinberger <[email protected]>
> ---
> arch/x86/entry/syscalls/syscall_64.tbl | 1 +
> include/linux/syscalls.h | 1 +
> kernel/sys.c | 35 ++++++++++++++++++++++++++++++++++
> kernel/sys_ni.c | 1 +
> 4 files changed, 38 insertions(+)
>
> diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl
> index cac6d17..f287712 100644
> --- a/arch/x86/entry/syscalls/syscall_64.tbl
> +++ b/arch/x86/entry/syscalls/syscall_64.tbl
> @@ -335,6 +335,7 @@
> 326 common copy_file_range sys_copy_file_range
> 327 64 preadv2 sys_preadv2
> 328 64 pwritev2 sys_pwritev2
> +329 common leftpad sys_leftpad
>
> #
> # x32-specific system call numbers start at 512 to avoid cache impact
> diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
> index d795472..a0850bb 100644
> --- a/include/linux/syscalls.h
> +++ b/include/linux/syscalls.h
> @@ -898,4 +898,5 @@ asmlinkage long sys_copy_file_range(int fd_in, loff_t __user *off_in,
>
> asmlinkage long sys_mlock2(unsigned long start, size_t len, int flags);
>
> +asmlinkage long sys_leftpad(char *str, char pad, char *dst, size_t dst_len);
> #endif
> diff --git a/kernel/sys.c b/kernel/sys.c
> index cf8ba54..e42d972 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -2432,3 +2432,38 @@ COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info)
> return 0;
> }
> #endif /* CONFIG_COMPAT */
> +
> +
> +SYSCALL_DEFINE4(leftpad, char *, src, char, pad, char *, dst, size_t, dst_len)

Have you considered /dev/leftpad instead?

2016-04-01 03:23:13

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] Implement leftpad syscall

Hi David,

[auto build test ERROR on v4.6-rc1]
[also build test ERROR on next-20160331]
[cannot apply to tip/x86/core]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url: https://github.com/0day-ci/linux/commits/Richard-Weinberger/Implement-leftpad-syscall/20160401-063620
config: microblaze-mmu_defconfig (attached as .config)
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=microblaze

All errors (new ones prefixed by >>):

kernel/sys.c: In function 'SYSC_leftpad':
>> kernel/sys.c:2441:2: error: implicit declaration of function 'strlen_user' [-Werror=implicit-function-declaration]
size_t len = strlen_user(src);
^
cc1: some warnings being treated as errors

vim +/strlen_user +2441 kernel/sys.c

2435
2436
2437 SYSCALL_DEFINE4(leftpad, char *, src, char, pad, char *, dst, size_t, dst_len)
2438 {
2439 char *buf;
2440 long ret;
> 2441 size_t len = strlen_user(src);
2442 size_t pad_len = dst_len - len;
2443
2444 if (dst_len <= len || dst_len > 4096) {

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (1.38 kB)
.config.gz (11.86 kB)
Download all attachments

2016-04-01 06:56:47

by Richard Cochran

[permalink] [raw]
Subject: Re: [PATCH] Implement leftpad syscall

On Fri, Apr 01, 2016 at 12:33:32AM +0200, Richard Weinberger wrote:
> From: David Gstir <[email protected]>
>
> Implement the leftpad() system call such that userspace,
> especially node.js applications, can in the near future directly
> use it and no longer depend on fragile npm packages.
>
> Signed-off-by: David Gstir <[email protected]>
> Signed-off-by: Richard Weinberger <[email protected]>
> ---
> arch/x86/entry/syscalls/syscall_64.tbl | 1 +
> include/linux/syscalls.h | 1 +
> kernel/sys.c | 35 ++++++++++++++++++++++++++++++++++
> kernel/sys_ni.c | 1 +
> 4 files changed, 38 insertions(+)

This is okay as far as it goes, but you need to add the other archs
and put the relevant maintainers onto CC.

Thanks,
Richard

2016-04-01 07:14:24

by Scott Bauer

[permalink] [raw]
Subject: Re: [PATCH] Implement leftpad syscall



On 03/31/2016 04:33 PM, Richard Weinberger wrote:
> From: David Gstir <[email protected]>
>
> Implement the leftpad() system call such that userspace,
> especially node.js applications, can in the near future directly
> use it and no longer depend on fragile npm packages.
>
> Signed-off-by: David Gstir <[email protected]>
> Signed-off-by: Richard Weinberger <[email protected]>
> ---
> arch/x86/entry/syscalls/syscall_64.tbl | 1 +
> include/linux/syscalls.h | 1 +
> kernel/sys.c | 35 ++++++++++++++++++++++++++++++++++
> kernel/sys_ni.c | 1 +
> 4 files changed, 38 insertions(+)
>
> diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl
> index cac6d17..f287712 100644
> --- a/arch/x86/entry/syscalls/syscall_64.tbl
> +++ b/arch/x86/entry/syscalls/syscall_64.tbl
> @@ -335,6 +335,7 @@
> 326 common copy_file_range sys_copy_file_range
> 327 64 preadv2 sys_preadv2
> 328 64 pwritev2 sys_pwritev2
> +329 common leftpad sys_leftpad
>
> #
> # x32-specific system call numbers start at 512 to avoid cache impact
> diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
> index d795472..a0850bb 100644
> --- a/include/linux/syscalls.h
> +++ b/include/linux/syscalls.h
> @@ -898,4 +898,5 @@ asmlinkage long sys_copy_file_range(int fd_in, loff_t __user *off_in,
>
> asmlinkage long sys_mlock2(unsigned long start, size_t len, int flags);
>
> +asmlinkage long sys_leftpad(char *str, char pad, char *dst, size_t dst_len);
> #endif
> diff --git a/kernel/sys.c b/kernel/sys.c
> index cf8ba54..e42d972 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -2432,3 +2432,38 @@ COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info)
> return 0;
> }
> #endif /* CONFIG_COMPAT */
> +
> +
> +SYSCALL_DEFINE4(leftpad, char *, src, char, pad, char *, dst, size_t, dst_len)
> +{
> + char *buf;
> + long ret;
> + size_t len = strlen_user(src);
> + size_t pad_len = dst_len - len;
> +
> + if (dst_len <= len || dst_len > 4096) {
> + return -EINVAL;
> + }
> +
> + buf = kmalloc(dst_len, GFP_KERNEL);
> + if (!buf)
> + return -ENOMEM;
> +
> + memset(buf, pad, pad_len);
> + ret = copy_from_user(buf + pad_len, src, len);
> + if (ret) {
> + ret = -EFAULT;
> + goto out;
> + }
> +
> + ret = copy_to_user(dst, buf, dst_len);
> + if (ret) {
> + ret = -EFAULT;
> + goto out;
> + }
> +
> + ret = pad_len;
> +out:
> + kfree(buf);
> + return ret;
> +}

This looks good, but since we want this to be as fast as possible we might just want to eliminate all
branches (Pesky bounds checks), and write directly into user memory to eliminate the pesky copy_from/copy_to. The second
idea would eliminate that slow kmalloc as well.

What do you think?

> diff --git a/kernel/sys_ni.c b/kernel/sys_ni.
> index 2c5e3a8..262608d 100644
> --- a/kernel/sys_ni.c
> +++ b/kernel/sys_ni.c
> @@ -175,6 +175,7 @@ cond_syscall(sys_setfsgid);
> cond_syscall(sys_capget);
> cond_syscall(sys_capset);
> cond_syscall(sys_copy_file_range);
> +cond_syscall(sys_leftpad);
>
> /* arch-specific weak syscall entries */
> cond_syscall(sys_pciconfig_read);
>

2016-04-01 08:06:14

by Richard Weinberger

[permalink] [raw]
Subject: Re: New syscall: leftpad()

Am 01.04.2016 um 01:36 schrieb Randy Dunlap:
> Please be more careful in your description...

I'm very sorry. Will do a v2 soon. ;-)

> On 03/31/16 15:33, Richard Weinberger wrote:
>> Recent happenings in the node.js community showed how fragile software is when
>> it comes to dependencies of fundamental algorithms like leftpad[1].
>> A node.js package which provided ledpad vanished and broke a lot of software.
>
> leftpad
>
>> This raised our attention and we came to the conclusion that it is the kernel's
>> job to provide such functionality such that node.js based applications can in future
>> rely in Linux's "don't break userspace" rule.
>> We hope that glibc and Andoid's bionic will soon offer wrapper functions for this
>
> Android's
>
>> new leftpad system call.
>> We put leftpad into the kernel not only because of Linux's stable ABI,
>> also for performance reasons.
>> As everyone knows, within the kernel everything is faster and better.
>> Leftpad has millions of users, so it has to be as fast as possible.
>> This new system call will also help making services like left-pad.io[2]
>> faster and more reliable. If the leftpad() system call gets adopted by a wider user base
>> it might also make sense to add a generic npm() system call which acts like ioctl()
>> where kernel modules can register new functions that are often used by node.js.
>> Such functions might be, is_array(), is_int(), etc.
>
>

Thanks,
//richard

2016-04-08 18:10:51

by Heinrich Schuchardt

[permalink] [raw]
Subject: Re: [PATCH] leftpad.2: Document new syscall

On 04/01/2016 12:33 AM, Richard Weinberger wrote:
> From: Daniel Walter <[email protected]>
>
> Signed-off-by: Daniel Walter <[email protected]>
> Signed-off-by: Richard Weinberger <[email protected]>
> ---
> man2/leftpad.2 | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 55 insertions(+)
> create mode 100644 man2/leftpad.2
>
> diff --git a/man2/leftpad.2 b/man2/leftpad.2
> new file mode 100644
> index 0000000..ff5f401
> --- /dev/null
> +++ b/man2/leftpad.2
> @@ -0,0 +1,55 @@
> +.\" Copyright (c) 2016 sigma-star gmbh
> +.\" ([email protected])
> +.\"
> +.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
> +.\" This is free documentation; you can redistribute it and/or
> +.\" modify it under the terms of the GNU General Public License as
> +.\" published by the Free Software Foundation; either version 2 of
> +.\" the License, or (at your option) any later version.
> +.\"
> +.\" The GNU General Public License's references to "object code"
> +.\" and "executables" are to be interpreted as the output of any
> +.\" document formatting or typesetting system, including
> +.\" intermediate and printed output.
> +.\"
> +.\" This manual is distributed in the hope that it will be useful,
> +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
> +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +.\" GNU General Public License for more details.
> +.\"
> +.\" You should have received a copy of the GNU General Public
> +.\" License along with this manual; if not, see
> +.\" <http://www.gnu.org/licenses/>.
> +.\" %%%LICENSE_END
> +.\"
> +.TH LEFTPAD 2 2016-04-01 "Linux" "Linux Programmer's Manual"
> +.SH NAME
> +leftpad
> +.SH SYNOPSIS
> +.nf
> +.B #include <sys/types.h>
> +
> +.BI "int leftpad(char *src, char pad, char *dst, size_t dst_len);
> +.fi
> +.SH DESCRIPTION
> +This function provides left padding for strings.
> +.LP
> +The string in
> +.I src
> +will be left padded with the chosen padding character
> +.I pad
> +and stored in
> +.I dst
> + .
> +.SH RETURN VALUE
> +On success, returns the number of padding characters added.
> +.SH ERRORS
> +.TP
> +.B EINVAL
> +The size of the destination buffer
> +.I dst
> +is shorter than the source string
> +.I src
> + . Or the destination string is longer than 4096 bytes.

Why should the call be limited to an arbitrary number of 4096 bytes?

There is no such limit in malloc so why should we need one here?

NAK

Best regards

Heinrich Schuchardt

> +.SH SEE ALSO
> +.BR snprintf (3)
>

2016-04-09 14:12:43

by Richard Weinberger

[permalink] [raw]
Subject: Re: [PATCH] leftpad.2: Document new syscall

Am 08.04.2016 um 20:10 schrieb Heinrich Schuchardt:
> On 04/01/2016 12:33 AM, Richard Weinberger wrote:
>> From: Daniel Walter <[email protected]>
>>
>> Signed-off-by: Daniel Walter <[email protected]>
>> Signed-off-by: Richard Weinberger <[email protected]>
>> ---
>> man2/leftpad.2 | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 55 insertions(+)
>> create mode 100644 man2/leftpad.2
>>
>> diff --git a/man2/leftpad.2 b/man2/leftpad.2
>> new file mode 100644
>> index 0000000..ff5f401
>> --- /dev/null
>> +++ b/man2/leftpad.2
>> @@ -0,0 +1,55 @@
>> +.\" Copyright (c) 2016 sigma-star gmbh
>> +.\" ([email protected])
>> +.\"
>> +.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
>> +.\" This is free documentation; you can redistribute it and/or
>> +.\" modify it under the terms of the GNU General Public License as
>> +.\" published by the Free Software Foundation; either version 2 of
>> +.\" the License, or (at your option) any later version.
>> +.\"
>> +.\" The GNU General Public License's references to "object code"
>> +.\" and "executables" are to be interpreted as the output of any
>> +.\" document formatting or typesetting system, including
>> +.\" intermediate and printed output.
>> +.\"
>> +.\" This manual is distributed in the hope that it will be useful,
>> +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> +.\" GNU General Public License for more details.
>> +.\"
>> +.\" You should have received a copy of the GNU General Public
>> +.\" License along with this manual; if not, see
>> +.\" <http://www.gnu.org/licenses/>.
>> +.\" %%%LICENSE_END
>> +.\"
>> +.TH LEFTPAD 2 2016-04-01 "Linux" "Linux Programmer's Manual"
>> +.SH NAME
>> +leftpad
>> +.SH SYNOPSIS
>> +.nf
>> +.B #include <sys/types.h>
>> +
>> +.BI "int leftpad(char *src, char pad, char *dst, size_t dst_len);
>> +.fi
>> +.SH DESCRIPTION
>> +This function provides left padding for strings.
>> +.LP
>> +The string in
>> +.I src
>> +will be left padded with the chosen padding character
>> +.I pad
>> +and stored in
>> +.I dst
>> + .
>> +.SH RETURN VALUE
>> +On success, returns the number of padding characters added.
>> +.SH ERRORS
>> +.TP
>> +.B EINVAL
>> +The size of the destination buffer
>> +.I dst
>> +is shorter than the source string
>> +.I src
>> + . Or the destination string is longer than 4096 bytes.
>
> Why should the call be limited to an arbitrary number of 4096 bytes?
>
> There is no such limit in malloc so why should we need one here?
>
> NAK

Sorry, the review window for this patch is now closed.
Please resend your comments on April 1st 2017.

Thanks,
//richard