* create_pathname - Create a path/file from some components * @dir: Directory in which to create the file * @dir2: Pathname to give the file (optional) * @name: Filename to give the file (optional) * @stream: Name of the stream (optional) * @buffer: Store the result here * @bufsize: Size of buffer * * Create a filename from various pieces. The output will be of the form:
| 772 | * Return: n Length of the allocated name |
| 773 | */ |
| 774 | static int create_pathname(const char *dir, const char *dir2, const char *name, |
| 775 | const char *stream, char *buffer, int bufsize) |
| 776 | { |
| 777 | char *namel; |
| 778 | if (name==NULL) |
| 779 | name = UNKNOWN; |
| 780 | namel=gen_local_filename(name); |
| 781 | if(dir2) |
| 782 | { |
| 783 | char *dir2l=gen_local_filename(dir2); |
| 784 | if (stream) |
| 785 | { |
| 786 | char *streaml=gen_local_filename(stream); |
| 787 | snprintf(buffer, bufsize, "%s/%s/%s:%s", dir, dir2l, namel, streaml); |
| 788 | free(streaml); |
| 789 | } |
| 790 | else |
| 791 | snprintf(buffer, bufsize, "%s/%s/%s", dir, dir2l, namel); |
| 792 | free(dir2l); |
| 793 | } |
| 794 | else |
| 795 | { |
| 796 | if (stream) |
| 797 | { |
| 798 | char *streaml=gen_local_filename(stream); |
| 799 | snprintf(buffer, bufsize, "%s/%s:%s", dir, namel, streaml); |
| 800 | free(streaml); |
| 801 | } |
| 802 | else |
| 803 | snprintf(buffer, bufsize, "%s/%s", dir, namel); |
| 804 | } |
| 805 | free(namel); |
| 806 | return strlen(buffer); |
| 807 | } |
| 808 | |
| 809 | /** |
| 810 | * open_file - Open a file to write to |
no test coverage detected