@@ -104,13 +104,9 @@ extern "C"
104104
105105 size_t PDALGetPipelineAsString (PDALPipelinePtr pipeline, char *buffer, size_t size)
106106 {
107- size_t result = 0 ;
108-
109107 if (pipeline && buffer && size > 0 )
110108 {
111109 Pipeline *ptr = reinterpret_cast <Pipeline *>(pipeline);
112- buffer[0 ] = ' \0 ' ;
113- buffer[size - 1 ] = ' \0 ' ;
114110
115111 try
116112 {
@@ -119,26 +115,23 @@ extern "C"
119115
120116 std::stringstream strm;
121117 pdal::PipelineWriter::writePipeline (ptr->manager ->getStage (), strm);
122- std::strncpy (buffer, strm.str (). c_str () , size - 1 );
123- result = std::min (strm.str (). length ( ), size);
118+ strm.get (buffer , size);
119+ return std::min (static_cast < size_t >( strm.gcount () ), size);
124120 }
125121 catch (const std::exception &e)
126122 {
127123 printf (" Found error while retrieving pipeline's string representation: %s\n " , e.what ());
124+ return 0 ;
128125 }
129126 }
130- return result ;
127+ return 0 ;
131128 }
132129
133130 size_t PDALGetPipelineMetadata (PDALPipelinePtr pipeline, char *metadata, size_t size)
134131 {
135- size_t result = 0 ;
136-
137132 if (pipeline && metadata && size > 0 )
138133 {
139134 Pipeline *ptr = reinterpret_cast <Pipeline *>(pipeline);
140- metadata[0 ] = ' \0 ' ;
141- metadata[size - 1 ] = ' \0 ' ;
142135
143136 try
144137 {
@@ -148,69 +141,62 @@ extern "C"
148141 std::stringstream strm;
149142 MetadataNode root = ptr->manager ->getMetadata ().clone (" metadata" );
150143 pdal::Utils::toJSON (root, strm);
151- std::strncpy (metadata, strm.str (). c_str () , size);
152- result = std::min (strm.str (). length ( ), size);
144+ strm.get (metadata , size);
145+ return std::min (static_cast < size_t >( strm.gcount () ), size);
153146 }
154147 catch (const std::exception &e)
155148 {
156149 printf (" Found error while retrieving pipeline's metadata: %s\n " , e.what ());
150+ return 0 ;
157151 }
158152 }
159- return result ;
153+ return 0 ;
160154 }
161155
162156 size_t PDALGetPipelineSchema (PDALPipelinePtr pipeline, char *schema, size_t size)
163157 {
164- size_t result = 0 ;
165-
166158 if (pipeline && schema && size > 0 )
167159 {
168160 Pipeline *ptr = reinterpret_cast <Pipeline *>(pipeline);
169161
170- schema[0 ] = ' \0 ' ;
171- schema[size - 1 ] = ' \0 ' ;
172-
173162 try
174163 {
175164 std::stringstream strm;
176165 MetadataNode meta = ptr->manager ->pointTable ().layout ()->toMetadata ();
177166 MetadataNode root = meta.clone (" schema" );
178167 pdal::Utils::toJSON (root, strm);
179- std::strncpy (schema, strm.str (). c_str () , size);
180- result = std::min (strm.str (). length ( ), size);
168+ strm.get (schema , size);
169+ return std::min (static_cast < size_t >( strm.gcount () ), size);
181170 }
182171 catch (const std::exception &e)
183172 {
184173 printf (" Found error while retrieving pipeline's schema: %s\n " , e.what ());
174+ return 0 ;
185175 }
186176
187177 }
188- return result ;
178+ return 0 ;
189179 }
190180
191181 size_t PDALGetPipelineLog (PDALPipelinePtr pipeline, char *log, size_t size)
192182 {
193- size_t result = 0 ;
194-
195183 if (pipeline && log && size > 0 )
196184 {
197185 Pipeline *ptr = reinterpret_cast <Pipeline *>(pipeline);
198- log[0 ] = ' \0 ' ;
199- log[size - 1 ] = ' \0 ' ;
200186
201187 try
202188 {
203- std::string s = ptr->logStream .str ();
204- std::strncpy (log, s.c_str (), size);
205- result = std::min (s.length (), size);
189+ ptr->logStream .get (log, size);
190+ return std::min (static_cast <size_t >(ptr->logStream .gcount ()), size);
206191 }
207192 catch (const std::exception &e)
208193 {
209194 printf (" Found error while retrieving pipeline's log: %s\n " , e.what ());
195+ return 0 ;
210196 }
211197 }
212198
213- return result ;
199+ return 0 ;
214200 }
215201
216202 void PDALSetPipelineLogLevel (PDALPipelinePtr pipeline, int level)
0 commit comments