| // Copyright 2019 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| // Returns the current user username. |
| const char* username = getenv("USER"); |
| return username ? std::string(username) : std::string(); |
| // Writes |string| to |stream| while escaping all C escape sequences. |
| void EscapeString(std::ostream* stream, const std::string& string) { |
| int main(int argc, char** argv) { |
| std::string username = Username(); |
| std::cout << "{\"username\": \""; |
| EscapeString(&std::cout, username); |
| std::cout << "\"}" << std::endl; |