I am creating a project I am thinking about open sourcing but I am concerned about the licensing issue of what exactly is trivial code. I am concerned because if I did not know how to do something I would just look online or in books for examples. If I was looking to learn how to implement some logical concept like a merge sort I would translate some pseudo-code into C or on the other hand if I was looking for the syntax form I would look at code snippets that does a certain operation i was interested in such as:

int copyfile(char *sourcepath,char *destpath)
    int dest_fd;
    int source_fd;
    int errorcode = 0;
    if((source_fd = open(sourcepath,O_RDONLY)) < 0)
        return 1;
    if((dest_fd = open(destpath,O_WRONLY|O_CREAT|O_TRUNC,0755)) <0)
        return 1;

    char *buf[4096];
    ssize_t readval;
    while((readval = read(source_fd,buf,sizeof(buf)) > 0))
        if(write(dest_fd,buf,readval) > 0)
           errorcode = 1;
    return errorcode;

Would something like this cause me an issue in licensing my project?

Addendum: I have a follow up question in the same vein and I thought that I should add it to this one over creating a whole new question. If this an incorrect conclusion let me know in the comments.

Basically the project im working on in my spare time to learn the in's and out's of a POSIX compliant system and the POSIX C library is basically reading the Single Unix Specification documents and trying to clean room re-implement them with the eventual goal of having a small fully compliant POSIX system capable of boot strapping itself without the dependency of the GNU tools and under a single license.

In this endeavor I've started to read classic UNIX and C works like the K & R book in which they explain fundamental concepts of the C language creating examples that are stripped down versions of Unix utilities and C stdlib function and more importantly some of the algorithms behind these functions as well as some what in my mind seem to be fundamental concepts of computer science.

Breaking this into two subquestions one dealing with what I would describe as fundamental concepts and the other dealing with well known algorithms.

1.a What is the delineation point between basic logical concepts and copyrighted code. Giving a few examples: (also these are off the top of my head from what I remember not directly copied just in case).

1.a.1 The standard library function strlen which returns the length of a string minus the null can be described like

int strlen(char *string)
    int i;
    for(i = 1;string[i] != NULL;i++)
    return i;

(Also I know strlen is of type size_t in the stdlib)


void swap(char *old,char *new)
    char *tmp = old;
    old = new;
    new = tmp;

Example 1.a.1 when boiled down to a simplistic child like definition is count each position until x is found.

Example 1.a.2 basically swap x with y and y with x.

Extracting the idea to the world of the physical my examples are respectively, count up a set number of items until you run out then stop leaving the last number said / though as how many items you have, and take one item and swap places with a second item. Which describe two skills / concepts a young child can understand.

Thus dove tailing back into my first subquestion. At what level does something go from programming something that is so fundamentally logically simplistic to something licensable. Would using a commonly used loop variable name like i or logical names like temp / tmp for temporary storage or string / str / s for string cause an issue or are these things so simplistic that it is classified as what someone in the comments below mentioned de minimis or the merger doctrine ?


This second subquestion falls under the category of seeing example implementations of basic algorithms I.e the type of things taught first or second year students in a principles of algorithmic design 101 class such as quick sort or binary search of which there are a very finite number of ways in which to go about implementing.

  • There's no objective rules for this. If you think it's going to be an issue you probably need to get a lawyer involved. Commented Feb 1, 2017 at 22:43
  • One example: if you have a bash script that just calls xargs 3 5 7, that may be hard to license, as your trying to claim creator ship of a program and a few odd numbers. I believe that is what is meant by "trivial".
    – Nate T
    Commented Nov 17, 2021 at 0:04

1 Answer 1


Some license texts provide some indication of what would be considered "trivial" amount of code.

numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length)

Yet, Oracle and Google have argued in US court over a nine-line rangeCheck function being copied.

So in this context, I personally consider that anything should be properly attributed as licensed and documented (including of course complying with the license) in particular code snippets from StackOverflow, books and man pages.

StackOverflow content has a clear CC-CY-SA license. Books code examples are either licensed under an open source license or are not licensed for reuse unless you obtain permission of the publisher. Man pages usually have a license, typically -but not always- the same license as the license of corresponding software.

In case of doubt and a clear license, I do always contact the author to obtain a clear and explicit permission: If anything out of fairness to the author that made the gift to publish their code in the first place.

Now, some consider that 3 lines or less is game for fair use. It could be that this is fair use and if this were the case it would still require proper credits and attribution (such as with comments) to document the provenance of the snippet.

So Would something like this cause me an issue in licensing my project?

There is no issue per se, but you should track what the license and author is for this snippet and properly credit this snippet (ideally adding some link too) and comply with whatever its license is.

If the license terms are missing, or unclear and the author cannot be reached for clarification, I would stay away from reusing this code.

  • 1
    What about stuff in books or man pages? Commented Feb 2, 2017 at 0:34
  • I added extra elements to my answer: the source of the copied snippet does not matter IMHO. Be it in print or man pages or doc or code or anything: copyrighted, it is. And license, it requires. :) Commented Feb 2, 2017 at 8:19
  • 4
    @ZenoofElea Two other relevant legal considerations here: de minimis (use so small it does not merit consideration under the law) and the merger doctrine (for an idea that can only be expressed in a very limited set of ways, the expression functionally is the idea, and therefore the expression is ineligible for copyright). Whether your use will satisfy either of these considerations is a legal determination.
    – apsillers
    Commented Feb 2, 2017 at 19:17
  • @apsillers excellent point! Commented Feb 3, 2017 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.