Giter VIP home page Giter VIP logo

mini-printf's People

Contributors

ihtnc avatar mludvig avatar peku33 avatar rainwoodman avatar superna9999 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mini-printf's Issues

License

Please specify a license for the code. Include a license file, specify the license in the readme, or put some license notice in the header of the files.

I recommend you a non-copyleft open source license like the BSD, Apache or MIT so this Software can be embedded in embedded applications that interact with other open source licenses or closed source, if you think is ok.

Kind regards

return value of mini_snprintf

I tried this library.

This code includes three printf() which emit 2, 7, 9 respectively.

I think the second mini_snprintf with %s format stores "hello\0" (\0 = null termination) but returns 5 (\0 excluded from the count).

I think this behavior is really surprising for users. How do you think? With this behavior, I think it is impossible to know that we reach the end of the buffer.

#include <stdio.h>
#include "mini-printf.h"

#define N 10
int main(void)
{
        char buf[N];
        int head = 0;
        head += mini_snprintf(buf + head, N - head, "%d", 10);
        printf("%d\n", head);
        // buf = 10
        head += mini_snprintf(buf + head, N - head, "%s", "hello");
        printf("%d\n", head);
        // buf = 10hello

        head += mini_snprintf(buf + head, N - head, "%s", "hello");
        printf("%d\n", head);
        // buf = 10hello\0he ????
        // expected: 10hellohel
        return 0;
}

Improvements with potential to be merged upstream?

Thanks for making this amazing library public.

I included a variant of mini-printf as part of my tinypy fork:

rainwoodman/tinypy@c4cae12

A few improvements:

  1. an extension interface for outsource %o and %O to an external function. (under an ifdef, so this is optional) The interface is not thread-safe. So there is space to improve it; but we may want to allow stubbing out the entire buff interface if thread safety is already a concern.

  2. always return the number of bytes would be written (excluding nul) even if that exceeds the size limit passed in. this is not posix though.

  3. support for 'ld' 'lu', 'lx', 'lX' as long types.

  4. padding of 's'.
    5, padding to more than 9 chars and padding with space.

I am wondering if you are interested in merging some of these features. If so I'll prepare a PR.

X and x prints as hexadecimal integer instead of unsigned integer

As specified in the printf man :

o, u, x, X
The unsigned int argument is converted to unsigned octal (o), unsigned decimal (u), or unsigned hexadecimal (x and X) notation. The letters abcdef are used for x conversions; the
letters ABCDEF are used for X conversions. The precision, if any, gives the minimum number of digits that must appear; if the converted value requires fewer digits, it is padded
on the left with zeros. The default precision is 1. When 0 is printed with an explicit precision 0, the output is empty.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.