All of lore.kernel.org
 help / color / mirror / Atom feed
* printk of non NULL terminated strings ?
@ 2020-07-09 12:31 Joakim Tjernlund
  2020-07-09 12:56 ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Joakim Tjernlund @ 2020-07-09 12:31 UTC (permalink / raw)
  To: linux-kernel

Is there a format (or other function) that lets me
print strings without an \0 terminator using an explicit length arg instead?

Something like:
  printk("%s...", str, str_len); /* replace ... */
or some other funktion perhaps ?

 Jocke

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: printk of non NULL terminated strings ?
  2020-07-09 12:31 printk of non NULL terminated strings ? Joakim Tjernlund
@ 2020-07-09 12:56 ` Andreas Schwab
  2020-07-09 13:26   ` Joakim Tjernlund
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2020-07-09 12:56 UTC (permalink / raw)
  To: Joakim Tjernlund; +Cc: linux-kernel

On Jul 09 2020, Joakim Tjernlund wrote:

> Is there a format (or other function) that lets me
> print strings without an \0 terminator using an explicit length arg instead?

Use the precision.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: printk of non NULL terminated strings ?
  2020-07-09 12:56 ` Andreas Schwab
@ 2020-07-09 13:26   ` Joakim Tjernlund
  2020-07-09 13:30     ` Rasmus Villemoes
  0 siblings, 1 reply; 5+ messages in thread
From: Joakim Tjernlund @ 2020-07-09 13:26 UTC (permalink / raw)
  To: schwab; +Cc: linux-kernel

On Thu, 2020-07-09 at 14:56 +0200, Andreas Schwab wrote:
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
> 
> 
> On Jul 09 2020, Joakim Tjernlund wrote:
> 
> > Is there a format (or other function) that lets me
> > print strings without an \0 terminator using an explicit length arg instead?
> 
> Use the precision.

Looking at that now but have a hard time figuring how to use it, can you give me an example?

 Jocke 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: printk of non NULL terminated strings ?
  2020-07-09 13:26   ` Joakim Tjernlund
@ 2020-07-09 13:30     ` Rasmus Villemoes
  2020-07-09 15:28       ` Joakim Tjernlund
  0 siblings, 1 reply; 5+ messages in thread
From: Rasmus Villemoes @ 2020-07-09 13:30 UTC (permalink / raw)
  To: Joakim Tjernlund, schwab; +Cc: linux-kernel

On 09/07/2020 15.26, Joakim Tjernlund wrote:
> On Thu, 2020-07-09 at 14:56 +0200, Andreas Schwab wrote:
>> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
>>
>>
>> On Jul 09 2020, Joakim Tjernlund wrote:
>>
>>> Is there a format (or other function) that lets me
>>> print strings without an \0 terminator using an explicit length arg instead?
>>
>> Use the precision.
> 
> Looking at that now but have a hard time figuring how to use it, can you give me an example?

Exactly as you'd do in userspace:

  printf("%.*s\n", len, buf)

Of course, vsnprintf() will still stop if it encounters a nul byte
within those first len bytes in buf. And you need len to have type int,
so you may need a cast if you have a size_t or ssize_t or whatnot.

Rasmus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: printk of non NULL terminated strings ?
  2020-07-09 13:30     ` Rasmus Villemoes
@ 2020-07-09 15:28       ` Joakim Tjernlund
  0 siblings, 0 replies; 5+ messages in thread
From: Joakim Tjernlund @ 2020-07-09 15:28 UTC (permalink / raw)
  To: rasmus.villemoes, schwab; +Cc: linux-kernel

On Thu, 2020-07-09 at 15:30 +0200, Rasmus Villemoes wrote:
> On 09/07/2020 15.26, Joakim Tjernlund wrote:
> > On Thu, 2020-07-09 at 14:56 +0200, Andreas Schwab wrote:
> > > CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
> > > 
> > > 
> > > On Jul 09 2020, Joakim Tjernlund wrote:
> > > 
> > > > Is there a format (or other function) that lets me
> > > > print strings without an \0 terminator using an explicit length arg instead?
> > > 
> > > Use the precision.
> > 
> > Looking at that now but have a hard time figuring how to use it, can you give me an example?
> 
> Exactly as you'd do in userspace:
> 
>   printf("%.*s\n", len, buf)
> 
> Of course, vsnprintf() will still stop if it encounters a nul byte
> within those first len bytes in buf. And you need len to have type int,
> so you may need a cast if you have a size_t or ssize_t or whatnot.

Thanks, this did the trick :)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-07-09 15:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-09 12:31 printk of non NULL terminated strings ? Joakim Tjernlund
2020-07-09 12:56 ` Andreas Schwab
2020-07-09 13:26   ` Joakim Tjernlund
2020-07-09 13:30     ` Rasmus Villemoes
2020-07-09 15:28       ` Joakim Tjernlund

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.