Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * C++ stream style string builder used in KUnit for building messages.
0004  *
0005  * Copyright (C) 2019, Google LLC.
0006  * Author: Brendan Higgins <brendanhiggins@google.com>
0007  */
0008 
0009 #ifndef _KUNIT_STRING_STREAM_H
0010 #define _KUNIT_STRING_STREAM_H
0011 
0012 #include <linux/spinlock.h>
0013 #include <linux/types.h>
0014 #include <linux/stdarg.h>
0015 
0016 struct string_stream_fragment {
0017     struct kunit *test;
0018     struct list_head node;
0019     char *fragment;
0020 };
0021 
0022 struct string_stream {
0023     size_t length;
0024     struct list_head fragments;
0025     /* length and fragments are protected by this lock */
0026     spinlock_t lock;
0027     struct kunit *test;
0028     gfp_t gfp;
0029 };
0030 
0031 struct kunit;
0032 
0033 struct string_stream *alloc_string_stream(struct kunit *test, gfp_t gfp);
0034 
0035 int __printf(2, 3) string_stream_add(struct string_stream *stream,
0036                      const char *fmt, ...);
0037 
0038 int __printf(2, 0) string_stream_vadd(struct string_stream *stream,
0039                       const char *fmt,
0040                       va_list args);
0041 
0042 char *string_stream_get_string(struct string_stream *stream);
0043 
0044 int string_stream_append(struct string_stream *stream,
0045              struct string_stream *other);
0046 
0047 bool string_stream_is_empty(struct string_stream *stream);
0048 
0049 int string_stream_destroy(struct string_stream *stream);
0050 
0051 #endif /* _KUNIT_STRING_STREAM_H */